Sha256: 25275d74b6b550fc78920b53b14846f0a92c476fb9812f4c1576b6f99e047be6

Contents?: true

Size: 810 Bytes

Versions: 9

Compression:

Stored size: 810 Bytes

Contents

class NSString

  # @return [UIImage]
  def uiimage
    UIImage.imageNamed(self).tap do |retval|
      NSLog("No image named #{self}") unless retval
    end
  end

  # @return [UIFont]
  def uifont(size=nil)
    size ||= UIFont.systemFontSize
    UIFont.fontWithName(self, size:size)
  end

  # @param font [UIFont] Optional, defaults to UIFont.systemFontOfSize(UIFont.systemFontSize)
  # @return [UILabel]
  def uilabel(font=nil)
    font ||= :system.uifont(UIFont.labelFontSize)
    size = self.sizeWithFont(font)
    UILabel.alloc.initWithFrame([[0, 0], size]).tap { |label|
      label.text = self
      label.font = font
      # why isn't this just the default!?
      label.backgroundColor = :clear.uicolor
    }
  end

  # @return [UIImageView]
  def uiimageview
    self.uiimage.uiimageview
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sugarcube-1.7.0 lib/sugarcube-uikit/nsstring.rb
sugarcube-1.6.3 lib/sugarcube-uikit/nsstring.rb
sugarcube-1.6.2 lib/sugarcube-uikit/nsstring.rb
sugarcube-1.6.1 lib/sugarcube-uikit/nsstring.rb
sugarcube-1.6.0 lib/sugarcube-uikit/nsstring.rb
sugarcube-1.5.9 lib/sugarcube-uikit/nsstring.rb
sugarcube-1.5.8 lib/sugarcube-uikit/nsstring.rb
sugarcube-1.5.7 lib/sugarcube-uikit/nsstring.rb
sugarcube-1.5.6 lib/sugarcube-uikit/nsstring.rb