Sha256: bcb566fe01b1fec2091afc90065eba8bb284997700c624a3eace24c0be97302e

Contents?: true

Size: 989 Bytes

Versions: 7

Compression:

Stored size: 989 Bytes

Contents

class NSString

  def nsurl
    @url ||= NSURL.alloc.initWithString(self)
  end

  def uiimage
    @uiimage = UIImage.imageNamed(self)
  end

  def uiimageview
    @uiimageview ||= (self.uiimage and self.uiimage.uiimageview or UIImageView.alloc.initWithImage(nil))
  end

  def uifont(size=UIFont.systemFontSize)
    @uifont ||= {}
    @uifont[size] ||= UIFont.fontWithName(self, size:size)
  end

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

    self.uiimage.uicolor(alpha)
  end

  # This can be called as `"Hello".localized` or `"Hello"._`.  The `str._`
  # syntax is meant to be reminiscent of gettext-style `_(str)`.
  def localized(value=nil, table=nil)
    @localized = NSBundle.mainBundle.localizedStringForKey(self, value:value, table:table)
  end
  alias :_ :localized

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sugarcube-0.7.6 lib/sugarcube/nsstring.rb
sugarcube-0.7.4 lib/sugarcube/nsstring.rb
sugarcube-0.7.3 lib/sugarcube/nsstring.rb
sugarcube-0.7.2 lib/sugarcube/nsstring.rb
sugarcube-0.7.1 lib/sugarcube/nsstring.rb
sugarcube-0.7 lib/sugarcube/nsstring.rb
sugarcube-0.6.1 lib/sugarcube/nsstring.rb