Dynamically change UILabel width not work with autolayout

前端 未结 1 1700
傲寒
傲寒 2021-02-06 04:29

I have some code:

CGRect currentFrame = textLabel.frame;
CGSize max = CGSizeMake(textLabel.frame.size.width, 3000);
CGSize expected = [[textLabel text] sizeWithF         


        
相关标签:
1条回答
  • 2021-02-06 05:33

    When using AutoLayout you should not update the frame property, instead modify the contraints on a view.

    On the other hand, you could also let AutoLayout work for you. Make sure the numberOfLines property of the label is set to 0 and the height constraint is of type Greater Than or Equal (>=). This way the layout will update automatically after setting new text on a label.

    0 讨论(0)
提交回复
热议问题