1

I have a UILabel which has a defined frame:

let label = UILabel(frame: someFrame)

Is it possible that the font size will be adjusted to fit the height of the bounding Rect or fit the height and width of the bounding rect?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Michael
  • 32,527
  • 49
  • 210
  • 370
  • there is a property called `adjustsFontSizeToFitWidth`, you could try. – Wingzero Jun 06 '15 at 02:14
  • Is there also one that adjusts with height? – Michael Jun 06 '15 at 02:17
  • Seems not. It is more complicated than you think to let font size fit rect I guess. What's your true problem? – Wingzero Jun 06 '15 at 02:26
  • 1
    The true problem is what I wrote. – Michael Jun 06 '15 at 02:38
  • I don't think you could fit the height and width without stretching or squashing the font. If you want to fit the height, I think you would have to loop through different font sizes until you get the one with the height that matches you label. This post proposes a solution, http://stackoverflow.com/questions/21270091/uilabel-adjust-font-size-to-height-with-autolayout/30656023#30656023 – rdelmar Jun 06 '15 at 04:51

1 Answers1

0

Set the label's font size to something absurdly large, then set the label's autoshrink to an absurdly small minimum font size. Now your label's font will always fit it's frame.

Jeff Hanna
  • 51
  • 4