寬高自適應
- (void)viewDidLoad {
[super viewDidLoad];
UIView * whiteView = [[UIView alloc] init];
whiteView.backgroundColor = [UIColor whiteColor];
UIView * containView = [[UIView alloc] init];
[containView addSubview:whiteView];
[self.scrollView addSubview:containView];
[self.view addSubview:self.scrollView];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(UIEdgeInsetsZero);
}];
[containView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.scrollView);
}];
[whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.offset(0);
make.right.bottom.mas_equalTo(1000);
}];
//這裏會修改contentSize
[containView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(whiteView.mas_right);
make.bottom.equalTo(whiteView.mas_bottom);
}];
}
複製代碼
高度自適應
- (void)viewDidLoad {
[super viewDidLoad];
UIView * whiteView = [[UIView alloc] init];
whiteView.backgroundColor = [UIColor whiteColor];
UIView * containView = [[UIView alloc] init];
[containView addSubview:whiteView];
[self.scrollView addSubview:containView];
[self.view addSubview:self.scrollView];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(UIEdgeInsetsZero);
}];
[containView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.scrollView);
make.width.equalTo(self.scrollView);
}];
[whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.offset(0);
make.bottom.mas_equalTo(1000);
}];
//高度自適應 這裏會修改contentSize
[containView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(whiteView.mas_bottom);
}];
}
複製代碼
寬度自適應
- (void)viewDidLoad {
[super viewDidLoad];
UIView * whiteView = [[UIView alloc] init];
whiteView.backgroundColor = [UIColor whiteColor];
UIView * containView = [[UIView alloc] init];
[containView addSubview:whiteView];
[self.scrollView addSubview:containView];
[self.view addSubview:self.scrollView];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(UIEdgeInsetsZero);
}];
[containView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.scrollView);
make.height.equalTo(self.scrollView);
}];
[whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.left.offset(0);
make.right.mas_equalTo(1000);
}];
//寬度自適應 這裏會修改contentSize
[containView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(whiteView.mas_right);
}];
}
複製代碼