Previous blog records How to use code to constrain the view, the original text: Click to open the link
This time, let's take a look at an example of automatic layout
1. Create a single View application:
2. Select Automatic Layout:
3. Drag two TextField and a button to the view, put them in the middle of the horizontal position of the screen, run:
Mobile phone vertical screen, it looks good:
It turns into the bird when it's sideways, ()
Of course you can add the constraints with the code, but with AutoLayout everything is so beautiful.
4. Select the two text field to set the vertical spacing,
Follow the above method to set it in sequence,
Three components of leading space to superview and trailing space to Superview
The bottom textfile and button vertical spacing
Top space to Superview top textfiled
After setting the constraint diagram as follows
All constraint lines must all turn blue, and if it is red the constraint is not set to complete,
You can click on the Red Arrows to see the missing constraints.
After Setup, the following results are run: