Masonry多视图约束
#import "ViewController.h"
#import "Masonry.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *redBtn = [UIButton buttonWithType:UIButtonTypeCustom];
redBtn.backgroundColor = [UIColor redColor];
[redBtn setTitle:@"按钮1" forState:UIControlStateNormal];
[self.view addSubview:redBtn];
UIButton *blueBtn = [UIButton buttonWithType:UIButtonTypeCustom];
blueBtn.backgroundColor = [UIColor blueColor];
[blueBtn setTitle:@"按钮2" forState:UIControlStateNormal];
[self.view addSubview:blueBtn];
UIButton *greenBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[greenBtn setTitle:@"按钮3" forState:UIControlStateNormal];
greenBtn.backgroundColor = [UIColor greenColor];
[self.view addSubview:greenBtn];
//使用Masonry不需要设置这个属性
greenBtn.translatesAutoresizingMaskIntoConstraints = NO;
// [redBtn mas_makeConstraints:^(MASConstraintMaker *make) {
// //
// }];
// [@[redBtn,blueBtn,greenBtn] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:90 leadSpacing:10 tailSpacing:10];
//MASAxisTypeHorizontal水平方向 三个按钮在同一水平线上
//宽、左、右 固定的
[@[redBtn,blueBtn,greenBtn] mas_makeConstraints:^(MASConstraintMaker *make) {
//统一设置按钮的top的约束
make.top.mas_equalTo(100);
make.height.mas_equalTo(50);
}];
[@[redBtn,blueBtn,greenBtn] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:10 leadSpacing:10 tailSpacing:10];
//水平方向 按钮的间距是固定的
//leading和tailling 固定的
}
@end
Masonry多视图约束.png
网友评论