【发布时间】:2012-10-15 14:13:07
【问题描述】:
[self.Review sizeToFit];
sizeToFit 之前的结果:
NSStringFromCGRect(self.Review.frame): {{90, 20}, {198, 63}}
sizeToFit 后的结果:
NSStringFromCGRect(self.Review.frame): {{90, 20}, {181, 45}}
我希望宽度保持不变。我只是想改变高度。自动掩码是
(lldb) po self.Review
(UILabel *) $1 = 0x08bb0fe0 <UILabel: 0x8bb0fe0; frame = (90 20; 181 45); text = 'I'm at Mal Taman Anggrek ...'; clipsToBounds = YES; opaque = NO; autoresize = LM+RM+H; userInteractionEnabled = NO; layer = <CALayer: 0x8bb68b0>>
我知道有一种方法可以做到这一点: How to adjust and make the width of a UILabel to fit the text size?
答案要么很奇怪(我们需要重新提供字体信息)。或者不清楚。
您还需要定义最大宽度,并告诉您的程序 如果 sizeToFit 为您提供的宽度大于该最大值,该怎么办。
我将使用sizeWithFont这个奇怪的解决方案。很奇怪,因为 UILabel 已经知道标签中的字体了。
实际上 sizeToFit 的行为如何?它如何决定我们需要更薄还是更高的 UILabel?
【问题讨论】:
-
sizeWithFont 是 NSString 的方法,而不是 UILable 的方法
标签: objective-c uilabel xcode4.5