Sha256: 90e60ab0ee82a6c29c3a984602a0fd01c04cdd4924346461978d4e40721fe5d5

Contents?: true

Size: 440 Bytes

Versions: 5

Compression:

Stored size: 440 Bytes

Contents

class NSArray

  # [160, 210, 242].uicolor => 0xA0D2F2.uicolor
  # [160, 210, 242, 0.5].uicolor => 0xA0D2F2.uicolor(0.5)
  def uicolor(alpha=nil)
    red = self[0] / 255.0
    green = self[1] / 255.0
    blue = self[2] / 255.0
    if self[3]
      alpha = self[3]
    end
    alpha ||= 1.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/nsarray.rb
sugarcube-1.6.3 lib/sugarcube-color/nsarray.rb
sugarcube-1.6.2 lib/sugarcube-color/nsarray.rb
sugarcube-1.6.1 lib/sugarcube-color/nsarray.rb
sugarcube-1.6.0 lib/sugarcube-color/nsarray.rb