问题
I have an instance of UILabel
with a default font 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.]
回答1:
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)
来源:https://stackoverflow.com/questions/6606998/uilabel-and-getting-the-size-after-autofit