Ways to implement AutoLayout using code 1
-Create constraints
+ (ID) Constraintwithitem: (ID) view1
Attribute: (Nslayoutattribute) attr1
Relatedby: (nslayoutrelation) relation
Toitem: (ID) view2
Attribute: (Nslayoutattribute) ATTR2
Multiplier: (cgfloat) multiplier
Constant: (cgfloat) C;
* View1: Controls to constrain
* ATTR1: Type of constraint (how to constrain)
* Relation: Relationship to the reference control
* View2: Referenced controls
* ATTR2: Type of constraint (how to constrain)
* Multiplier: Multiplier
* C: constant
-Add Constraint
-(void) AddConstraint: (Nslayoutconstraint *) constraint;
-(void) Addconstraints: (Nsarray *) constraints;
-Note
-Be sure to add a constraint after owning the parent control
-Turn off autoresizing function
View.translatesautoresizingmaskintoconstraints = NO;
Ways to implement AutoLayout using code 2-VFL
-Create an array of constraints using the VFL
+ (Nsarray *) Constraintswithvisualformat: (NSString *) format
Options: (nslayoutformatoptions) opts
Metrics: (nsdictionary *) metrics
Views: (Nsdictionary *) views;
* FORMAT:VFL Statement
* OPTs: Constraint type
* Specific values used in the METRICS:VFL statement
* Controls used in VIEWS:VFL statements
-Use the following macro to automatically generate views and metrics parameters
Nsdictionaryofvariablebindings (...)
Ways to implement AutoLayout using code 3-masonry
-Use steps
-Add all the source code of the masonry folder to the project
-Add 2 macros, import the primary header file
As soon as you add this macro, you don't have to take the Mas_ prefix
#define Mas_shorthand
As soon as you add this macro, Equalto is equivalent to Mas_equalto
#define Mas_shorthand_globals
This header file must be placed behind the top two macros
#import "Masonry.h"
-Methods for adding constraints
This method will only add new constraints.
[View makeconstraints:^ (Masconstraintmaker *make) {
}];
This method will delete all previous constraints and add new constraints
[View remakeconstraints:^ (Masconstraintmaker *make) {
}];
This method will overwrite some of the previous specific constraints
[View updateconstraints:^ (Masconstraintmaker *make) {
}];
-Types of constraints
1. Size: width\height\size
2. Boundary: Left\leading\right\trailing\top\bottom
3. Center point: center\centerx\centery
4. Boundary: Edges
-TableView How to display data
-Set DataSource data source
-Data source to comply with Uitableviewdatasource protocol
-Data sources to implement some of the methods in the Protocol
/**
* Tell TableView how many sets of data there are
*/
-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView
/**
* Tell TableView how many lines are in section group
*/
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section
/**
* Tell TableView what kind of cell Indexpath line shows
*/
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath
/**
* Tell TableView header of section group
*/
-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) Section
/**
* Tell TableView the trailing title of section group
*/
-(NSString *) TableView: (UITableView *) TableView titleforfooterinsection: (nsinteger) Section
```
iOS Edge Learning-three ways to introduce layouts