IOS AutoLayout Automatic Layout Intermediate Development tutorial (2)-First Knowledge AutoLayout

Source: Internet
Author: User

Through storyboard, we first know the manifestation of AutoLayout:

See, two control views created with storyboard:


The distance value within the four rounded corners of the box is a constraint;

For example, the second view, his constraints are: distance from the left side of the view, the right side of the distance, so that the width and the horizontal direction of the position, as well as the distance above (the first) view, and high, so that the height of the view and the y-axis position, so that you can be in a two-dimensional space The only way to determine the location of this view;

However, it is important to note that the position of the first view must be determined when you add a constraint from the bottom boundary of the previous view, otherwise the position of the second view may not be in the appropriate position.

How do I add a constraint? Not much to say directly:


After you select a view, click the second button in the lower right corner of the graph to add constraints to the view;

For example, the added constraint is: distance from the left and right boundary distance, the upper boundary distance above the view distance, height constraint;

Add to complete the carriage return, or add;

Description

1. Be sure to select one or more boundary values to complete before changing their values, otherwise, you may be able to change the value and then select Other constraints, you changed the value of the resurgence;

2. Four constraints to determine the location of the view, try not to repeat the addition, but not conflict

The hook on the front of the 3.constrain to margin is removed, otherwise a blank area is left on the left and right edges of the view

4.Equal width equal width, Equal heights and so on, that is, the view can be added between the equal width of the constraint, a height can be equal to the height of B

5.Aspect Ratio, want to keep the proportions, for example you want to keep the ratio as long as 1:1 you can tick this; this corresponds to a proportional scaling, which will be mentioned later, is now one of the iOS layout solutions

6.Align reserved boundaries

7.Update Frames Choose the scenario in the diagram as much as possible, and then update the location constraints of the view when you are finished.

Now we have succeeded in adding a constraint to a view

Description

Boundary constraint, which is a constraint on the parent view, (dependent on the parent view, the parent view disappears, and the constraint disappears)

The constraint of the width and height is the constraint of the view itself;

How do I view and modify constraints?:


Look at the picture, you can know how to view and modify the value of the constraint, this is Autolaout's first experience, more exciting, advanced section in the next tutorial!

IOS AutoLayout Automatic Layout Intermediate Development tutorial (2)-First Knowledge AutoLayout

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.