I have a UILabel set with a font of system bold 14.0, a minimum font size of 12. I want the label to fill 7 lines, and if it's too big, shrink the text down to 12 pixels, in which case it might be more than 7 lines, but still fit in it's original frame.
I've tried setting the number of lines to 7 and to 0. Either way the text just fills the 7 lines at the default size (14) and truncates the tail. How can I get the text to shrink down to 12px so that I can see more text?
(I would post more code, but most of these are set in IB).
EDIT: I have the Autoshrink option set to "Minimum Font Size" with a size of 12. Even if I set this to something obvious like 8, no shrinkage happens.
Check with
sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:
[labelText sizeWithFont:labelFont
minFontSize:12.0
actualFontSize:&returnFontSize
forWidth:frame.size.width
lineBreakMode:UILineBreakModeWordWrap];
For more details check apple documentation for NSString
. There are some other convenience methods also available for the NSString
.
Update: Based on your edit, a work around for your issue is to set the following property,
label.adjustsFontSizeToFitWidth = YES;
You can use .adjustsFontSizeToFitWidth=YES
this will adjust the font size to fit the width of the label. For example, if you have a label with numberOfLines=2
and the text is too long, the font size of the label will be reduced to fit all the text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With