Masonr布局对UIScrollView的内容自适应
1.添加UIscrollview到self.view上,并设置约束等于父视图,设置宽度。
self.scrollView.backgroundColor = [UIColor grayColor];
[self.view addSubview:self.scrollView];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(100);
make.left.right.equalTo(self.view);
make.bottom.equalTo(self.view);
}];
2.使用容器视图添加到UIscrollview上,所有的子视图布局在这个容器视图上。
[self.scrollView addSubview:self.contentView];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.scrollView);
make.width.equalTo(self.scrollView);
}];
[self.contentView addSubview:self.labTitle02];
[self.labTitle01 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView.mas_top).offset(10);
make.width.mas_equalTo(kScreenWidth-20);
make.centerX.equalTo(self.contentView);
}];
[self.labTitle02 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.labTitle01.mas_bottom).offset(10);
make.width.mas_equalTo(kScreenWidth-20);
make.centerX.equalTo(self.contentView);
}];
3.设置布局的最底部的视图,容器视图的bottom等于最后一个视图的bottom
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.labTitle03.mas_bottom).offset(30);
}];