Sha256: 4a07108ec77ca0a231d1f41c9569a26fc37df12635c87bb9ea47eee76f764b57

Contents?: true

Size: 1.02 KB

Versions: 9

Compression:

Stored size: 1.02 KB

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.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

    begin
      self.to_sym.uicolor(alpha)
    rescue SugarNotFoundException
      self.uiimage.uicolor(alpha)
    end
  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

9 entries across 9 versions & 1 rubygems

Version Path
sugarcube-0.6 lib/sugarcube/nsstring.rb
sugarcube-0.5 lib/sugarcube/nsstring.rb
sugarcube-0.4.2 lib/sugarcube/nsstring.rb
sugarcube-0.4.1 lib/sugarcube/nsstring.rb
sugarcube-0.4 lib/sugarcube/nsstring.rb
sugarcube-0.3.2 lib/sugarcube/nsstring.rb
sugarcube-0.3.1 lib/sugarcube/nsstring.rb
sugarcube-0.3.0 lib/sugarcube/nsstring.rb
sugarcube-0.2.5 lib/sugarcube/nsstring.rb