开发者

UILabel and getting the size after autofit

开发者 https://www.devze.com 2023-03-19 00:16 出处:网络
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.

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消