Disclaimer: This is my study notes, if there are mistakes in the wrong place can be a message to discuss together
The visual build UI is very efficient, so the official Apple is also highly recommended. So let's learn how to use the system's own story version (storyboard) to build the UI. Visual build UI You can use Xib in addition to using storyboard. It's also very easy to use them, just write the name of the control in the lower right corner of Xcode and drag it onto the storyboard.
After dragging and dropping. is to set the size of the control according to the requirements, as well as the screen adaptation (Iphone4~iphone 6s Plus) and so on. In this set size point, we are going to use the constraint. The previous use of code also uses constraints to constrain the size of each control. so the concept of restraint does not begin to speak. (if you really don't want to use constraints, you can actually implement a screen.) can be set in proportion to the size, similar to H5). Now the main talk about how to implement, how to operate, add constraints to the control.
I'm going to drag a uiview to set a constraint at the top of the distance.
After this is set up, you will see the following phenomenon
There is a red note and a lack of constraint is not added. The top line is the constraint we added. If we write first, the distance from the top is 133. Then we can switch to which screen size is 133.
We add a constraint to the left and then set its width height to 100. That
When you're done with the restraints.
The size and position of the UIView after this constraint is fixed. It will be the same regardless of which screen is changed later.
However, there is a drawback, the location and size of its distance is absolute rather than relative. If you use iphone4 to show this interface, you feel biased, then use iphone6s will appear almost or just fine, with examples to see,
So, we should use relative position and relative size. If we want it to be centered horizontally, we delete the original left constraint and add a horizontal center constraint.
This is centered horizontally. Run and see.
This is centered horizontally. Since the relative constraints, of course, more than just the horizontal center, for example, I want to the left point to do? What about the right point? To change the horizontal center factor,
Click on the edit to change the multiplier, that is the coefficient value, than 1 small is to the left, than the 1 is to the right, we set the effect of 0.6 and 1.8 to see
Isn't that obvious? Then we can set the position we need according to the actual demand. Vertical centering is also set. is to check the horizontal constraint under the one (vertically)
After writing the relative position, we should think about how to set the relative size. In order to facilitate the demonstration, first deleted the original, and re-pull a uiview. Set its size and screen to equal high width.
Put equal widths and equal heights tick on can, add up on it. That's it after setup.
Just because we haven't added a position constraint, we give it 0.0 on the left and the top, so we can do it.
OK, the relative size can be achieved here.
Similarly, we want to modify it not full screen size, or use coefficients
Modified to 0.4 try
The same as the width of the high, want to learn slowly oneself to engage in.
In learning this, we have learned to constrain the absolute and to add the relative values. The next combinations will look at the actual needs of the project and your various imaginations. Come on!
iOS note ui--using storyboard to add constraints