Sha256: b9d5f43a8511b78226fcba8a55cb8e7648f63d78cf43a776aa9e9dd8b2123380

Contents?: true

Size: 828 Bytes

Versions: 55

Compression:

Stored size: 828 Bytes

Contents

class Fixnum

  #     0xffeedd.uicolor
  # =>
  #     UIColor.colorWithRed(0xFF / 255.0, green: 0xEE / 255.0, blue: 0xDD / 255.0, alpha: 1.0)
  #     # ≈ UIColor.colorWithRed(1.0, green: 0.933, blue: 0.867, alpha: 1.0)
  #
  #     0xffeedd.uicolor(0.25)
  # =>
  #     UIColor.colorWithRed(0xFF / 255.0, green: 0xEE / 255.0, blue: 0xDD / 255.0, alpha: 0.25)
  #     # ≈ UIColor.colorWithRed(1.0, green: 0.933, blue: 0.867, alpha: 0.25)
  def uicolor(alpha=nil)
    alpha = 1.0 if alpha.nil?

    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)
    uicolor(alpha).CGColor
  end

  def skcolor(alpha=nil)
    uicolor(alpha)
  end

end

Version data entries

55 entries across 55 versions & 2 rubygems

Version Path
sugarcube-4.0.0 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.5.0 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.4.2 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.4.1 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.4.0 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.3.7 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.3.6 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.3.5 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.3.4 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.3.3 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.3.2 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.3.1 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.3.0 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.2.0 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.1.1 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.1.0 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.0.8 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.0.7 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.0.6 lib/ios/sugarcube-color/fixnum.rb
sugarcube-3.0.5 lib/ios/sugarcube-color/fixnum.rb