布局等宽高等间隔的一组view
2019-12-09 本文已影响0人
cochn
masonry:
`
[self.view addSubview:self.redView];
[self.view addSubview:self.blueView];
[self.view addSubview:self.blackView];
CGFloat top = 80;
CGFloat padding = 20;
[self.redView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.offset(top);
make.left.offset(padding);
make.height.mas_equalTo(self.redView.mas_width).multipliedBy(1);
}];
[self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.redView);
make.left.mas_equalTo(self.redView.mas_right).offset(padding);
make.height.mas_equalTo(self.redView);
make.width.mas_equalTo(self.redView);
}];
[self.blackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.blueView);
make.left.mas_equalTo(self.blueView.mas_right).offset(padding);
make.height.mas_equalTo(self.blueView);
make.width.mas_equalTo(self.blueView);
make.right.offset(-padding);
}];
[self.view layoutIfNeeded];
NSLog(@"%@\n%@\n%@",NSStringFromCGRect(self.redView.frame),NSStringFromCGRect(self.blueView.frame),NSStringFromCGRect(self.blackView.frame));
`
当padding = 20时:
屏幕快照 2019-12-09 上午11.00.18.png
当padding = 3时:
屏幕快照 2019-12-09 上午11.03.08.png
现象:当padding = 20时,views的宽度并不是严格相等,当padding=3时,views的宽度相等
结论:当屏幕宽度减去所有padding后,view的宽度如果可以均分则均分,如果不能,系统自动处理,且保留小数到.5
xib:同上