先看看Masonry的源代码,可以发现两个属性 这两个属性可以设置视图中的宽高比例 使用multipliedBy必须是对同一个控件本身,比如,上面的代码中,我们都是对bottomInnerView.mas_width本身的,如果修改成相对于其它控件,会出问题。
//multipler属性表示约束值为约束对象的乘因数- (MASConstraint * (^)(CGFloat multiplier))multipliedBy;//dividedBy属性表示约束值为约束对象的除因数,可用于设置view的宽高比- (MASConstraint * (^)(CGFloat divider))dividedBy;复制代码
具体使用
// width/height比为1/3.0,要求是同一个控件的属性比例 [bottomInnerView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.mas_equalTo(bottomView); make.center.mas_equalTo(bottomView); // 注意,这个multipliedBy的使用只能是设置同一个控件的,比如这里的bottomInnerView, // 设置高/宽为3:1 make.height.mas_equalTo(bottomInnerView.mas_width).multipliedBy(3); make.width.height.mas_equalTo(bottomView).priorityLow(); make.width.height.lessThanOrEqualTo(bottomView); }];复制代码