#import "ViewController.h"
#import "Masonry.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIView *blueView = [[UIView alloc]init];
blueView.backgroundColor = UIColor.blueColor;
[self.view addSubview:blueView];
UIView *greenView = [[UIView alloc]init];
greenView.backgroundColor = UIColor.greenColor;
[self.view addSubview:greenView];
//mas_makeConstraints 添加约束
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
//trailing 右侧 equalTo相对于哪个视图 offset 约束值
make.trailing.equalTo(self.view).offset(-50);
//equalTo() 参数必须是对象 如果约束相对于父视图的话 可以使用下面的写法
make.bottom.equalTo(@(-50));
make.width.equalTo(@100);
//mas_equalTo()参数可以使基础类型
make.height.mas_equalTo(60);
}];
[greenView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(blueView.mas_leading).offset(-60);
make.bottom.mas_equalTo(blueView.mas_top).offset(-60);
make.width.mas_equalTo(blueView);
make.height.mas_equalTo(60);
}];
//删除旧约束 跟新新约束
// [greenView mas_remakeConstraints:^(MASConstraintMaker *make) {
//
// }];
//更新约束
// [greenView mas_updateConstraints:^(MASConstraintMaker *make) {
//
// }];
}
@end
Masonry简单介绍.png
网友评论