You need to set the label.adjustsFontSizeToFitWidth = YES;
In addition to what the other answers say, if you put minSize/defaultSize (division) as the minimumScaleFactor
, it will be the same as using the old minimumFontSize
.
Ex, if you want the minimum font size to be 10 using default label size, you can do:
[label setMinimumScaleFactor:10.0/[UIFont labelFontSize]];
(Replace [UIFont labelFontSize]
with your label's font size if it is not the default).
which would be the same as:
[label setMinimumFontSize:10.0];
According to the documentation:
Use this property to specify the smallest multiplier for the current font size that yields an acceptable font size to use when displaying the label’s text. If you specify a value of 0 for this property, the current font size is used as the smallest font size.
So if default font size for your label is 10
, you put 0.7f
as a minimumScaleFactor
and it should do the same thing as minimumFontSize
did.
In addition to other answers, I'm going to add a beginner-friendly explanation that helped myself:
How to calculate a minimumScaleFactor
? Divide your label's minimum font size by your label's default font size. For example, your default font size is 25. Your minimum font size is 10.
10/25 = 0.4
0.4 is your minimumScaleFactor
value. Also see @Jsdodgers's answer above.
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