IOS uses constraint to achieve 2 controls the white space is equal

Source: Internet
Author: User

It's a little messy, let's take a look at the picture.

In fact, the purpose of this constrant is to control the size of white space above and below the two square controls.

For each block, the blanks above and below them are the same. This "center" design is visible everywhere. A control wants to achieve this centering and simple, just need to create a reference view, such as here H1 or H2, and then adjust the height of the reference view, finally set the control and the reference view in the middle of the alignment. 2 consecutive controls want to implement, just a little trouble, need 2 reference view, the specific setting method, please refer to. Note that the m,n,height here are fixed values. So the corresponding H1 and H2 can unlock a unique set of values, so the central y-coordinate of the 2 controls is unique, meaning the set of constraint can achieve the goal!

But the above method is not good, here is mainly to give a judge can use constraint to determine the location of the method, here is the use of equations, to solve the specific value.

Look at a really good way to see

Here the height of the 2 controls is fixed, one is M, and the other is N. After adding 3 auxiliary view, these 3 view does not set the specific height, but uses constraint to string up these 5 view, and sets 2 constraint, thus, has the following equation

M+N+H1+H2+H3 = Total Height

H1 = H2 = 0.3*h3

This will solve the h1,h2,h3, so the position of the control is determined, and the blank spacing of the 2 controls can be adjusted according to our needs.

Related Article

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.