UILabel and getting the size after autofit

不想你离开。 提交于 2019-12-08 08:15:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!