如何计算iOS 7中的实际字体点大小(不是边界矩形)? [英] How to calculate actual font point size in iOS 7 (not the bounding rectangle)?
本文介绍了如何计算iOS 7中的实际字体点大小(不是边界矩形)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
编辑:链接的重复问题仅涉及计算文本矩形。我需要在标签缩放后计算实际字体大小,而不是字符串大小。
此方法现已弃用:
size = [self sizeWithFont:font // 20
minFontSize:minFontSize // 14
actualFontSize:&actualFontSize // 16
forWidth:maxWidth
lineBreakMode:self.lineBreakMode];
当缩小文本大小时,如何在iOS 7中计算UILabel的字体大小适合吗?
How can I calculate font size of a UILabel now in iOS 7 when it shrunk the size of the text to fit in?
推荐答案
我遇到同样的问题,我需要知道实际大小才能让其他UILabel在我身上UIView比赛。
I have the same problem, I need to know the actual size to make that the others UILabels in my UIView match.
我知道这不是一个完美的解决方案,但也许它对你有用。
I know that it's not a perfect solution, but perhaps it's useful for you.
我的解决方案是:而不是使用 adjustsFontSizeToFitWidth
我计算手动大小。
My solution is: instead of use adjustsFontSizeToFitWidth
I calculate "manually" the size.
CGSize initialSize = [_label.text sizeWithAttributes:@{NSFontAttributeName:_label.font}];
while ( initialSize.width > _label.frame.size.width ) {
[_label setFont:[_label.font fontWithSize:_label.font.pointSize - 1]];
initialSize = [_label.text sizeWithAttributes:@{NSFontAttributeName:_label.font}];
}
CGFloat actualSize = _label.font.pointSize;
这篇关于如何计算iOS 7中的实际字体点大小(不是边界矩形)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文