iOS开发-Masonry约束宽高比

先看看Masonry的源代码,能够发现两个属性 这两个属性能够设置视图中的宽高比例 使用multipliedBy必须是对同一个控件自己,好比,上面的代码中,咱们都是对bottomInnerView.mas_width自己的,若是修改为相对于其它控件,会出问题。bash

//multipler属性表示约束值为约束对象的乘因数
- (MASConstraint * (^)(CGFloat multiplier))multipliedBy;

//dividedBy属性表示约束值为约束对象的除因数,可用于设置view的宽高比
- (MASConstraint * (^)(CGFloat divider))dividedBy;
复制代码

具体使用less

// 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);
  }];

复制代码
相关文章
相关标签/搜索