我的故事板使用AutoLayout,我将UILabel
拖到UIViewController
,并设置它的numberOfLines
属性为0,而不设置其约束。
当我尝试使用代码更改其高度时,但它不起作用。
在ViewController.m中
#define MXGetScreenWidth [[UIScreen mainScreen] bounds].size.width
- (void)viewDidLoad {
[super viewDidLoad];
NSString *text = @"Why not work, I was so sad in my deep heart. I need to study hard, talk less and work more.";
NSMutableAttributedString *contentAttributedString = [[NSMutableAttributedString alloc] initWithString:text];
[contentAttributedString addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16.f]}
range:NSMakeRange(0, text.length)];
CGSize contentSize = [contentAttributedString boundingRectWithSize:CGSizeMake(MXGetScreenWidth-10*2, 60)
options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin
context:nil].size;
self.tipsLabel.frame = CGRectMake(10, 52, MXGetScreenWidth-10*2,
tipsSize.height>=25.f?tipsSize.height:25.f);
}
iOS9发生了什么?谢谢你的宝贵答案。
答案 0 :(得分:0)
启用AutoLayout
后,请尝试以下操作:
[label setPreferredMaxLayoutWidth:MXGetScreenWidth];