Autolayout allows you to assign a value directly to the label without calculating the width and height of the text. The label automatically adjusts the width and height of the text.
If you specify the topmargin and left margin of the label
The bottom margin is set to> = 300.
Then re-set the label content in viewdidload. At this time, you will find that the label will automatically increase
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ _label.text = @"aaaaaaaaaaaasfeaqrgrthrwthwrtyjhwryjwryjwryjwryjwryjwryjwryjwrytjwryjwrytjwrytjwrtjwrtyjwrtjwrtjqwrtjwrtjhwrtjhetjrthjqwrthjqrthqrthjqrtjhqrtjhqarthjqethjteqathqtehqthqathqrthqrtjhq"; });
In addition, the label provides a property preferredmaxlayoutwidth to obtain the width used to calculate the text height. If this property is not set, it will be calculated according to the settings in autolayout.
If this attribute is reset, the value is used to calculate the height of the label to be changed.
Change the above Code to the following code.
_label.preferredMaxLayoutWidth = 1000; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ _label.text = @"aaaaaaaaaaaasfeaqrgrthrwthwrtyjhwryjwryjwryjwryjwryjwryjwryjwrytjwryjwrytjwrytjwrtjwrtyjwrtjwrtjqwrtjwrtjhwrtjhetjrthjqwrthjqrthqrthjqrtjhqrtjhqarthjqethjteqathqtehqthqathqrthqrtjhq"; });
We set preferredmaxlayoutwidth to 1000. When the label content is changed, re-calculate the height and the maximum width will be 1000.
Then the calculated height is definitely not enough (because the width is about 300 beforehand, and the calculated height is about 1/3 of the normal height). Let's see the dizzy row effect after setting the attribute.
Therefore, the calculated height is not enough. As a result, the label cannot be used to multiply all texts...
Autolayout ~ Label