Masonry使用指南
引入头文件
#import <Masonry.h>
利用例子
UIView *blueView = [[UIView alloc] init];
UIView *redView = [[UIView alloc] init];
[self addSubview: redView];
[self addSubview: blueView];
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(150);
make.height.mas_equalTo(50);
make.top.equalTo(self).offset(100);
make.left.equalTo(self).offset(30);
}];
[redView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(30);
make.centerY.equalTo(blueView.mas_centerY);
make.left.equalTo(blueView.mas_right).offset(20);
make.right.equalTo(self.mas_right).offset(-30);
}];
redView.backgroundColor = UIColor.redColor;
blueView.backgroundColor = UIColor.blueColor;
注意要先把redView和blueView添加到父视图中,再用Masonry进行操作
不然会报错:
2020-11-10 21:43:57.269861+0800 only-UI-travel-APP[7141:67655] *** Assertion failure in -[MASViewConstraint install], /Users/student14/Documents/only-UI-travel-APP/Pods/Masonry/Masonry/MASViewConstraint.m:343

浙公网安备 33010602011771号