Because I also began to learn automatic layout, so there may be errors, please include a lot, and point out the error
With regard to automatic layout, many introductions are now made with Xib and storyboard, but the use of pure code AutoLayout is getting less
Below the main general introduction of the next few days to learn the pure code use AutoLayout Some of the possible useful things.
First create 3 UIView
and initialize the view.
To adjust the layout of the child view before using automatic layout, use the
translatesautoresizingmaskintoconstraints The attribute of this uiview and set it to No
Ok! The preparatory work has been finished, and the following starts to get to the point
First, we have to achieve this effect.
There are 3 different ways
1. Adding constraints using the VFL language
2. Adding a constraint to one
3. Adding constraints for a set of groups
I. Adding a constraint using the VFL language
Add these constraints to run the program, to achieve the beginning of the effect
Comments:
|: Represents the parent view
-: Indicates distance
V:: Indicates vertical
H:: Indicates level
>=: Indicates that the view spacing, width, and height must be greater than or equal to a value
<=: Indicates that the view spacing, width, and height must be small or equal to a value
= =: Indicates that the view spacing, width, or height must be equal to a value
@: >=, <=, = = limit maximum of 1000
1.|-[view]-|: The view is within the left and right edges of the parent view
2.|-[view]: View is in the left edge of the parent view
3.| [view]: Align the view to the left of the parent view
4.-[view]-: Setting the width height of the view
5.|-30.0-[view]-30.0-|: Indicates left and right distance from parent view 30
6.[view (200.0)]: Indicates a view width of 200.0
7.|-[view (View1)]-[view1]-| : Represents the width of the view and is within the left and right edges of the parent view
8. V:|-[view (50.0)]: view height is 50
9:v:|-(==padding)-[imageview]->=0-[button]-(==padding)-| : Represents the distance from the parent view
For padding, the two view spacing must be greater than or equal to 0 and the distance from the bottom parent view is padding.
: [Wideview (>[email protected]): The width of the view is at least 60 and cannot exceed 700
11: If no declaration direction defaults to horizontal V:
2. Adding a constraint to one
The main use of this method
-(void) AddConstraint: (Nslayoutconstraint *) constraint;
This can also achieve the effect of using the VFL language
3. Adding constraints for a set of groups
The main use of this method
-(void) Addconstraints: (Nsarray *) constraints;
The above 3 methods can achieve the above effect, but it is not difficult to find that 2, 3 methods of code is far greater than the first, in practice I would like you to use the first method.
Adaptive layout-Introduction to this place, in the future there will be more detailed explanation.
Things to do with iOS pure code Auto-layout (introduction)