Masonry is an iOS adaptation of the third-party library, the more useful one, I use not much, a simple understanding of some common methods, their own learning, record down mutual encouragement.
Masonry:
Https://github.com/SnapKit/Masonry
Example one: View Center processing
In any case, the view is in the center state
__weak typeof (self) weakself = self;
UIView * view = [UIView new];
View.backgroundcolor = [Uicolor Redcolor];
[Self.view Addsubview:view];
// Adding a constraint using mas_makeconstraints
[View mas_makeconstraints:^ (Masconstraintmaker *make) {
// add size constraint ( make is the control you want to add the constraint to view,size is set the view size )
Make.size.mas_equalTo (Cgsizemake (100, 100));
// Add center constraint (centered with self , center set to center)
Make.center.equalTo (Weakself.view);
}];
Example two: A constraint between two view
Add a new view
UIView * Blackview = [UIView new];
Blackview.backgroundcolor = [Uicolor blackcolor];
[Self.view Addsubview:blackview];
Add a constraint to a black view
[Blackview mas_makeconstraints:^ (Masconstraintmaker *make) {
// Add size constraint (set black view size to 100,size to width)
Make.size.mas_equalTo (Cgsizemake (100, 100));
// add left, top margin constraints (both left and top constraints are 20,left.and.top to set both the left margin and margin )
Make.left.and.top.mas_equalTo (20);
}];
Masonry recording--ios adaptation