Sha256: 45fd4db7a09f6ed7bf33ad808cf3afdb0f0dd5022079faf324b666927a84d090

Contents?: true

Size: 713 Bytes

Versions: 52

Compression:

Stored size: 713 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 = NSLineBreakByWordWrapping

    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: NSLineBreakByWordWrapping)
    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

52 entries across 52 versions & 1 rubygems

Version Path
sugarcube-3.0.4 lib/ios/sugarcube-ui/uilabel.rb
sugarcube-3.0.3 lib/ios/sugarcube-ui/uilabel.rb
sugarcube-3.0.2 lib/ios/sugarcube-ui/uilabel.rb
sugarcube-3.0.1 lib/ios/sugarcube-ui/uilabel.rb
sugarcube-3.0.0 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.12.3 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.12.2 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.12.1 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.12.0 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.11.1 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.11.0 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.10.0 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.9.1 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.8.2 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.8.1 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.8.0 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.7.1 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.7.0 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.6.0 lib/ios/sugarcube-uikit/uilabel.rb
sugarcube-2.5.0 lib/ios/sugarcube-uikit/uilabel.rb