Autolayout ~ Label

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.