Use StoryBoard to create three buttons, buttons, horizontally, and so on

With apple Storyboard promotion and support function, Storyboard is more and more powerful, whether it is personal development or teamwork, Storyboard’s performance is good, but some pure code layout is relatively easy to implement, especially related to the screen adaptation and screen rotation.

Use StoryBoard to create three buttons, buttons, horizontally, and so on
needs to be implemented

Recently encountered in the development needs in a View level display three buttons, button and the distance between both sides is equal to the distance to the border button, before meeting directly on the pure code to create, get the screen width after direct calculation (assuming the button width and height fixed), the rotation of the screen should also be refreshed again.

Note: Tip here, iOS8 screen rotation time [UIScreen mainScreen].bonuns changes, access to the screen width should be in the following way

MIN (SCREEN_HEIGHT, SCREEN_WIDTH);

StackOverflow-iOS8 screen.

So in storyboard how to use constraints to achieve? It’s really simple

The basic design idea of Use StoryBoard to create three buttons, buttons, horizontally, and so on

As shown above, in fact, is the use of equal width constraint in order to realize. 3 buttons, in the center of the middle, between the button and the button and the screen between 4 intervals, the spacing to equal ~ ~ then put 4 view view, set the width between the two equal.

Ok, know how to design, the following step by step, first drag three Button, width constraint set button, here is 70, 70. Then set the middle button with the parent view horizontally and vertically centered to make sure it is in the center.

And other two button and button intermediate level center, after 4 view in drag filled in the gap, set 4 view and the parent view alignment, about two view and 4 view parent view alignment constraint is similar

Use StoryBoard to create three buttons, buttons, horizontally, and so on
4 view constraints

Note, do not set the width constraint 4 view, but 4 view width, the width of the screen so that they will be with the change.

Set after the completion of operation.

Use StoryBoard to create three buttons, buttons, horizontally, and so on
vertical screen

Rotating screen

Use StoryBoard to create three buttons, buttons, horizontally, and so on
under the screen

Can see 4 view width change, hide after 4 view be accomplished.

When little button can be played, without having to manually change the constraints, when the button is still a lot of time with the appropriate code.

Above.