- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIView *container = [UIView new];
[self.view addSubview:container];
container.backgroundColor = [UIColor blueColor];
[container mas_makeConstraints:^(MASConstraintMaker *make) {
//高度自适应,由子view的高度决定。此处切勿设置高度约束。
make.top.equalTo(self.view).offset(100);
make.left.equalTo(self.view).offset(10);
make.right.equalTo(self.view).offset(-10);
}];
UIView *subView = [UIView new];
[container addSubview:subView];
subView.backgroundColor = [UIColor orangeColor];
[subView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(container).offset(10);
make.height.equalTo(@200);
make.left.equalTo(container).offset(10);
make.right.equalTo(container).offset(-10);
//用于撑开container。注意不要设置container高度相关的约束。
make.bottom.equalTo(container).offset(-10);
}];
}