I have a UILabel
measuring 984x728 px with variable text. How can I calculate the maximum font size to fit the UILabel
?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
will hold the largest size less than 48 and greater than 0 that will fit within maxWidth
.