Sha256: e3ac2e982165ceb5a41920c159bd70c4f0c23ad5e89a7ca9c660c15e40ba1a21

Contents?: true

Size: 714 Bytes

Versions: 72

Compression:

Stored size: 714 Bytes

Contents

class UILabel
	
  # forces the given text to fit inside the label's frame starting at a given font size 
  def fit_to_size(max_size)
    #enforce word wrap
    self.lineBreakMode = UILineBreakModeWordWrap
    
    dynamic_font = self.font.fontWithSize(max_size + 2)
    constraintSize = CGSizeMake(self.frame.size.width, 10000)

    # does it fit yet?
    begin
      dynamic_font = dynamic_font.fontWithSize(dynamic_font.pointSize - 2)
      current_size = self.text.sizeWithFont(dynamic_font, constrainedToSize:constraintSize, lineBreakMode:UILineBreakModeWordWrap)
    end while self.frame.size.height <= current_size.height

    #now set to font size we have settled on
    self.font = dynamic_font

  end

end

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
sugarcube-2.0.1 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.0.0 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-1.7.0 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.6.3 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.6.2 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.6.1 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.6.0 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.5.9 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.5.8 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.5.7 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.5.6 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.5.5 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.5.4 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.5.3 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.5.2 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.5.1 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.5.0 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.4.6 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.4.5 lib/sugarcube-uikit/uilabel.rb
sugarcube-1.4.4 lib/sugarcube-uikit/uilabel.rb