PDA

View Full Version : Multi-line UILabel adjustFontSizeToFitWidth




admanimal
Aug 23, 2008, 10:49 AM
Has anyone figured out how to get the auto font size adjustment to work for a UILabel when it has numberOfLines set to more than one? It seems to just ignore adjustFontSizeToFitWidth if the label has more than one line.



siva.d
Oct 2, 2008, 01:01 AM
Thanks in advance,

I want to display text in more than one line, can any one help me.

Thank you
siva.d

PhoneyDeveloper
Oct 2, 2008, 10:24 AM
Did you read the comment in UILabel.h where it says that adjustsFontSizeToFitWidth only works if lineCount is 1?

Niiro13
Oct 2, 2008, 11:21 AM
So in other words, you'll have to use a UITextView which has a dynamic number of lines but fixed font size.

PhoneyDeveloper
Oct 2, 2008, 12:19 PM
Dynamic number of lines with a fixed font size is exactly what UILabel gives you if you set the numberOfLines to zero. The usual reason to use adjustsFontSizeToFitWidth is if you have a fixed size for the label and you want all the text to fit. If you can allow the label to be any height then you don't need that.

Also you could probably use sizeWithFont:constrainedToSize:lineBreakMode to find the font size that will show all the text in a multiline label and then set that font size for the label.