wayneh wayneh - 1 year ago 138
iOS Question

How to set font size to fill UILabel height?

I've seen a bunch of examples for changing the size of a UILabel (thanks).

Here's what I'd like to do:
Change the font size so that the text will be as large as possible within the new height.

Any clues?

Answer Source

Edit: Check out Joel Fischer's great answer to programmatically obtain the correct size!

You can set the font to automatically fill the size of a label, and optionally not go below a minimum font size. Just set adjustsFontSizeToFitWidth to YES. Check out the UILabel Class Reference if you need more information.

Although the boolean is called "adjustsFontSizeToFitWidth," it really means the largest size for the height of the label, that will stay on one line of the label (or however many lines you specify).