Sha256: 2da06dfc03400321ecf0f443bc09d46ed7074047bc3107b40d25f2a0592fe0ad

Contents?: true

Size: 402 Bytes

Versions: 5

Compression:

Stored size: 402 Bytes

Contents

class NSString

  # @return [UIColor]
  def uicolor(alpha=nil)
    if self[0,1] == '#'
      if self.length == 4
        return (self[1] * 2 + self[2] * 2 + self[3] * 2).to_i(16).uicolor(alpha)
      end
      return self[1..-1].to_i(16).uicolor(alpha)
    end

    img = UIImage.imageNamed(self)
    img && img.uicolor(alpha)
  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/nsstring.rb
sugarcube-1.6.3 lib/sugarcube-color/nsstring.rb
sugarcube-1.6.2 lib/sugarcube-color/nsstring.rb
sugarcube-1.6.1 lib/sugarcube-color/nsstring.rb
sugarcube-1.6.0 lib/sugarcube-color/nsstring.rb