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.
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);
So in storyboard how to use constraints to achieve? It’s really simple
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
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.
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.