Uilabel's autolayout~

Source: Internet
Author: User

First create a new project, drag a label in, and then let NumberOfLines = 0

And then put it in the controller.

Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (2 * nsec_per_sec)), Dispatch_get_main_queue (), ^ {        @ "aaaaaaaaaaaasfeaqrgrthrwthwrtyjhwryjwryjwryjwryjwryjwryjwryjwrytjwryjwrytjwrytjwrtjwrtyjwrt JWRTJQWRTJWRTJHWRTJHETJRTHJQWRTHJQRTHQRTHJQRTJHQRTJHQARTHJQETHJTEQATHQTEHQTHQATHQRTHQRTJHQ";    }); 

Operation, the effect is as follows

If you don't add a constraint, setting an excessive amount of content to Uilabel won't change his frame

2. Add top constraint and left constraint two constraints

Run again

Will find the following results

The label is stretched, and we print out its frame to see that it stretches very long, 1385.5; in fact, it can be guessed that this is almost the total length of the text set

, or you can use the system's API to calculate it.

3. Now add the constraints on the left and right three directions, as

Run the program again and you'll find the label is not wider, but you're getting taller.

Such as

Similarly, if you add the upper and lower left constraints, the label will be highly constant, the length of the longer, in short, the label will extend to the place without constraints, specific to, and priority horizontal extension, and horizontal extension of the case, the label text is always a line, timely label height enough, will not become more than a row

4. In the second case, if the label adds only the upper left constraint, the text that is set above the label length is extended wirelessly on the landscape, but has a property

Preferredmaxlayoutwidth can be set, label the maximum width used when calculating height (autolayout and label numberoflines = 0)

can also be set in IB, as follows

Fill in a value in the inside. Then tick the check box on the back, and run the program

Although the label does not have the right constraint (or width constraint), the label width is not extended horizontally, but is extended horizontally by the value you just filled out, and it automatically becomes multiple lines, and the content is self-adapting.

At this point the value of the preferredmaxlayoutwidth limit is 200, we now add the right limit to the label, 10 units of length from the parent control

The results of the operation are as follows

At this point we can see that the width of the label is determined by the constraints set by the AutoLayout, and the height is calculated based on the set preferredmaxlayoutwidth = 200, so the label is up and down margin

Uilabel's autolayout~

Related Keywords:

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.