I have an instance of UILabel
with a default f开发者_开发问答ont size of 28
and minimum font size of 16
. I allow the font to auto-adjust to fit subject to this minimum and with one line only.
Suppose I have some text in the UILabel
that has been automatically adjusted to fit. How do I get the new font size, or to be more precise the scale factor applied to the label's content?
[NB. The font property does not change under autofit.]
I'm afraid that this calculation is done at draw time and not accessible (at least using public apis)
But you should be able to calculate it using one of UIKit
sizeWithFont:
methods, like UILabel
does. (Beware that text metrics are CPU consuming... like when using them in a table cell)
精彩评论