当字体大小很大时,iOS 7 Autolayout无法正确调整UILabel的大小

时间:2014-12-31 21:13:42

标签: ios7 alignment uilabel xcode6 autolayout

我在这里使用了解决方案(UILabel sizeToFit doesn't work with autolayout ios6)来使UILabel适合文本。 enter image description here

然而,当我增加字体大小时,高度不再适合。
enter image description here

我不熟悉排版,但我猜文本边界框内的填充始终存在,而且当字体大小很小时,它就不明显了。

在我的项目中,UILabel中的文本在两种字体之间切换,填充的差异使得它很难与同一视图上的其他控件对齐。

所以我的问题是,如何摆脱大字体大小的UILabel中的padding-top和padding-bottom?

1 个答案:

答案 0 :(得分:-1)

简单地说,你不能。 但是,您可以使用以下公式

相应地减少Height字体
Int heightToDecrease = FontSize - 12;  //Change the value to fit your font family.
lblText.frame = CGRectMake(lblText.frame.origion.x, lblText.frame.origion.y, lblText.frame.size.width, lblText.frame.size.height - heightToDecrease);

我知道这不是完美的解决方案,但它肯定会帮助你。