如何计算UILabel的字体大小? [英] How can I calculate font size for my UILabel?
本文介绍了如何计算UILabel的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 UILabel
测量984x728 px与可变文本。如何计算最大字体大小以适应 UILabel
?
I have a UILabel
measuring 984x728 px with variable text. How can I calculate the maximum font size to fit the UILabel
?
推荐答案
创建一个比你想要的大的字体(48分大概是好的)。然后使用:
Create a font larger than you would ever want (48 points is probably good). Then use this:
CGFloat maxFontSize;
[string sizeWithFont:font minFontSize:0 actualFontSize:&maxFontSize forWidth:maxWidth lineBreakMode: UILineBreakModeClip];
maxFontSize
48和大于0,将适合 maxWidth
。
maxFontSize
will hold the largest size less than 48 and greater than 0 that will fit within maxWidth
.
这篇关于如何计算UILabel的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文