开发者

How can I calculate font size for my UILabel?

开发者 https://www.devze.com 2023-04-01 12:03 出处:网络
I have a UILabel measuring 984x728 px with variable text. How can I calculate the maximum font开发者_如何学编程 size to fit the UILabel?Create a font larger than you would ever want (48 points is prob

I have a UILabel measuring 984x728 px with variable text. How can I calculate the maximum font开发者_如何学编程 size to fit the UILabel?


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.

0

精彩评论

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

关注公众号