- 让两个高度为150的view垂直居中且等宽且等间隔排列 间隔为10
UIView * view2 = [UIView new];
[view1 addSubview:view2];
view2.backgroundColor = [UIColor colorWithRed:0.667 green:1.000 blue:0.247 alpha:1.000];
UIView * view3 = [UIView new];
view3.backgroundColor = [UIColor colorWithRed:0.705 green:1.000 blue:0.435 alpha:1.000];
[view1 addSubview:view3];
int padding1 = 10;
[view2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(view1.mas_centerY);
make.left.equalTo(view1.mas_left).with.offset(padding1);
make.right.equalTo(view3.mas_left).with.offset(-padding1);
make.height.mas_equalTo(@130);
make.width.equalTo(view3);
}];
[view3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(view1.mas_centerY);
make.left.equalTo(view2.mas_right).with.offset(padding1);
make.right.equalTo(view1.mas_right).with.offset(-padding1);
make.height.mas_equalTo(@130);
make.width.equalTo(view2);
}];
// 添加一个button
UIButton *button = [[UIButton alloc]init];
[button setBackgroundColor:[UIColor colorWithRed:0.526 green:0.898 blue:1.000 alpha:1.000]];
[self.view addSubview:button];
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(50);
make.left.equalTo(self.view).offset(100);
make.right.equalTo(self.view).offset(-100);
make.bottom.equalTo(view.mas_top).offset(-100);
}];
[button addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
Masonry初级基本用法就差不多了
总的效果图如下:
屏幕快照 .png
网友评论