Masonry is a third-party framework that encapsulates Apple AutoLayout. Simplifies code addition constraints, and so on.
:
Https://github.com/SnapKit/Masonry
After downloading the unzip, drag the masonry folder into the project.
Here's a small example:
First import the header file:
#import "Masonry/Masonry.h"
[[UIView alloc]init]; [buleView setBackgroundColor:[UIColor blueColor]]; [self.view addSubview:buleView]; [buleView mas_makeConstraints:^(MASConstraintMaker *make) { //大小 make.size.mas_equalTo(CGSizeMake(5050)); //位置:居中 make.center.mas_equalTo(self.view); }];
Run, there is a 50*50 blue small square in the center of the screen.
Masonry some of the constraints inside the method:
[buleView mas_makeConstraints:^(MASConstraintMaker *make) { //添加新约束 }]; [buleView mas_remakeConstraints:^(MASConstraintMaker *make) { //会把以前的约束删除掉,添加新的约束 }]; [buleView mas_updateConstraints:^(MASConstraintMaker *make) { //更新以前的约束 }];
An example of referencing a masonry document:
The effect is a view that has a 10 margin between the top and bottom of the parent control. The official list of two types of writing, the second direct sentence to achieve results.
The first type:
Uiedgeinsets padding = Uiedgeinsetsmake (Ten,Ten,Ten,Ten);[View1 mas_makeconstraints:^ (Masconstraintmaker *make) {Make. Top. Equalto(Superview. Mas_top). with. Offset(padding. Top);//with is an optional semantic fillerMake. Left. Equalto(Superview. Mas_left). with. Offset(padding. Left);Make. Bottom. Equalto(Superview. Mas_bottom). with. Offset(-padding. Bottom);Make. Right. Equalto(Superview. Mas_right). with. Offset(-padding. Right);}];
The second type:
[view1 mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(superview).with.insets(padding);}];
Here we will encounter a lot of mas_ prefixes and do not have this prefix of things, the difference between them is that with Mas_ prefix is the parameters are encapsulated, for example:
Mas_equalto (100)
Equalto (@100)
No mas_ prefixes need to be transferred to the type, or vice versa.
If you want to equate these two effects, then masonry provides two macros for us to use, but it is important to note that when defining this macro, before importing the masonry header file, for example:
constantiftofordefaultconstantiftouse‘mas"Masonry/Masonry.h"
That's all you can do.
iOS Development-masonry