How can I calculate font size for my UILabel?

断了今生、忘了曾经 提交于 2020-01-06 04:01:05

问题


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.



来源:https://stackoverflow.com/questions/7241116/how-can-i-calculate-font-size-for-my-uilabel

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