I have a label of length
100. This is the maximum label size i can have.
When i display a text of 10 characters it fits to it. But at times i will have to display more than 10 characters
. So is there a way to shrink the the font
size and make it to fit in my UILabel
of length 100 ?
UILabel *la = [UILabel alloc]initWithFrame(5,10,100,14)];
Just use the adjustsFontSizeToFitWidth property of UILabel [Reference].
la.adjustsFontSizeToFitWidth = YES;
From the reference:
Normally, the label text is drawn with the font you specify in the font property. If this property is set to YES, however, and the text in the text property exceeds the label’s bounding rectangle, the receiver starts reducing the font size until the string fits or the minimum font size is reached. This property is effective only when the
numberOfLines
property is set to1
.The default value for this property is
NO
. If you change it toYES
, you should also set an appropriate minimum font size by modifying theminimumFontSize
property.
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