Sha256: 5ecea18e1b24d7410704f93304a27843c008de23667723bdf54353d86d1c9468

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

class UIImage
  def uiimage ; self ; end

  def uicolor(alpha=nil)
    color = UIColor.colorWithPatternImage(self)
    if not alpha.nil?
      color = color.colorWithAlphaComponent(alpha.to_f)
    end

    color
  end

  def uiimageview
    @uiimageview = UIImageView.alloc.initWithImage(self)
  end

  ##|
  ##|  REALLY HANDY STUFF!
  ##|
  def scale_to new_size
    UIGraphicsBeginImageContextWithOptions(new_size, false, 0.0)
    self.drawInRect([[0, 0], new_size])
    image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return image
  end

  def rounded(corner_radius=5)
    UIGraphicsBeginImageContext(size)
    path = UIBezierPath.bezierPathWithRoundedRect([[0, 0], size], cornerRadius:corner_radius)
    path.addClip
    self.drawInRect([[0, 0], size])
    image = UIGraphicsGetImageFromCurrentImageContext()

    UIGraphicsEndImageContext()
    return image
  end

  def tileable
    resizableImageWithCapInsets(UIEdgeInsetsZero, resizingMode:UIImageResizingModeTile)
  end

  def stretchable
    resizableImageWithCapInsets(UIEdgeInsetsZero, resizingMode:UIImageResizingModeStretch)
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sugarcube-0.11.3 lib/sugarcube/uiimage.rb
sugarcube-0.11.2 lib/sugarcube/uiimage.rb
sugarcube-0.11.1 lib/sugarcube/uiimage.rb