AutoLayout is an "automatic layout" technique designed to lay out the UI interface AutoLayout easy to solve the two core concepts of screen adaptation issues AutoLayout: >1 reference: Set the current control location and size by referencing another control or parent control > 2 constraint constraints (rule): Restricting control location and size by adding constraints
Code Implementation
AutoLayout
the steps: 1. Use the Nslayoutconstraint class to create a specific constraint object 2. Add constraint object to the corresponding view-(void) AddConstraint: (Nslayoutconstraint *) constraint;-(void) addconstraints: (Nsarray *) Constraints
- Code Implementation AutoLayout points of attention:
1 "To disable the Autoresizing function first, set the following property for the view to Noview.translatesautoresizingmaskintoconstraints = NO;2" before adding constraints, Make sure that the controls are already on their parent control. 3 No more setting frame to view a Nslayoutconstraint object represents a common method for creating constrained objects
+ (ID) Constraintwithitem: (ID) view1 attribute: (nslayoutattribute) attr1 Relatedby: ( Nslayoutrelation) Relation Toitem: (ID) view2 attribute: (nslayoutattribute) attr2 multiplier: (cgfloat) Multiplier constant: (cgfloat) C;
View1: Control to constrain ATTR1: type of constraint (how to constrain) relation: Relationship to reference control View2: Referenced control attr2: type of constraint (how to constrain) multiplier: Multiplier C: constant
Automatic layout has a core formula: Obj1.property1 = (Obj2.property2 * multiplier) + constant value
Automatic Layout in iOS