Sha256: f4ba0d258751be5b3297415d2d44045d7ad7a4ddcb106e9c1dcb5af3e4c13db7

Contents?: true

Size: 539 Bytes

Versions: 5

Compression:

Stored size: 539 Bytes

Contents

class Fixnum

  #     0xffffff.uicolor
  #     0xffffff.uicolor(0.33)
  # =>
  #     UIColor.colorWithRed(1.0, green:1.0, blue: 1.0, alpha:1.0)
  #     UIColor.colorWithRed(1.0, green:1.0, blue: 1.0, alpha:0.33)
  def uicolor(alpha=nil)
    alpha ||= 1.0

    red = ((self & 0xFF0000) >> 16).to_f / 255.0
    green = ((self & 0xFF00) >> 8).to_f / 255.0
    blue = (self & 0xFF).to_f / 255.0

    UIColor.colorWithRed(red, green:green, blue:blue, alpha:alpha.to_f)
  end

  def cgcolor(alpha=nil)
    self.uicolor(alpha).CGColor
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sugarcube-1.7.0 lib/sugarcube-color/fixnum.rb
sugarcube-1.6.3 lib/sugarcube-color/fixnum.rb
sugarcube-1.6.2 lib/sugarcube-color/fixnum.rb
sugarcube-1.6.1 lib/sugarcube-color/fixnum.rb
sugarcube-1.6.0 lib/sugarcube-color/fixnum.rb