Storyboard的UILabel多行文本在iOS 9中不起作用

时间:2015-10-02 16:15:59

标签: objective-c storyboard uilabel

我的故事板使用AutoLayout,我将UILabel拖到UIViewController,并设置它的numberOfLines属性为0,而不设置其约束。

当我尝试使用代码更改其高度时,但它不起作用。

请看下面的图片: enter image description here enter image description here

在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发生了什么?谢谢你的宝贵答案。

1 个答案:

答案 0 :(得分:0)

启用AutoLayout后,请尝试以下操作:

[label setPreferredMaxLayoutWidth:MXGetScreenWidth];