IOS AutoLayout Auto-layout Intermediate Development Tutorials (3)-equal width and other high centers

Source: Internet
Author: User

There are some knowledge about boundary constraints, but the basic knowledge to solve some practical problems will be a bit too much, so we need a more advanced way to set constraints, such as the setting of high-width centers:

See:



The figure has 3 button buttons, now requires 3 button, such as width, and so on, and the vertical center on a line, how to set?

According to the previous statement, the constraint is actually a solution of a equations, then through the observation can be obtained, if we set the button between the left and right boundary constraints, and then let 3 button, such as width can be;

Then there will be 3x = width; So the width of each button can be calculated to add a top constraint to button1

Specific practices:

First set the boundary constraint between the buttons (do not update Frames first), assuming that all are 20,


Equal width try:

Select Button2, and Control-drag a line to button1 the following options appear:



Choose Equal widths equal width, Equal heights and so on, center y vertical Center equals (may be slightly biased, centery value can be adjusted!) The default center y is the one that determines your current location.

Button 3 is similar to the operation, then you can want to button1,2,3 will be on the same level, the width of the height is equal!

The effect is as follows:



As you can see, there are buttons with the same width height, but why is button 3 not with the other two button on a horizontal line?

This is because the center Y default value is adjusted to your actual location, so if you need to align horizontally, you need to change the value of CenterY to 0!

Modify the value of center Y to

As you can see, the key point of this setting is: control-drag from one view to another (including parent view) to generate, wide, center, and boundary relationships!

We need to adjust the value according to the actual situation!

Even if the constraints you just set are equal widths, you can adjust the width of each button arbitrarily, as


Can change its value, the principle is similar to from 3x = K, to 1x +1.5x +2x =k is the same truth, then the width of each view even out!

To summarize:

We can set the relationship of two views by holding down CONTROL and dragging on another view.

Add:

Center x can be set, with a horizontal center between two views (including child and parent views) on one line:

As the center x is equal to some of the views, you can see a long line of hints!

Drag from Button4 to his parent view to see the following options, or drag to the left View list (more options!)


Drag and drop to see the following options:



We choose Center horizontally ... You can set the center of the Button4 with the parent view (or other view) the horizontal center is on a line!

Center Vert ... It's center Y, and the vertical center is equal

PS: If you need to move around, or move online, just change the value of center X or Center Y!



Change all center x and Center y to 0 to see the following effects:


Original Address http://blog.csdn.net/yangbingbinga/article/details/43069341


IOS AutoLayout Auto-layout Intermediate Development Tutorials (3)-equal width and other high centers

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.