这个要根据情况而定,有时会很有用的。

  • setContentHuggingPriority: 优先级越高,代表压缩越厉害,越晚被拉伸。就是上图中那人拉的力量更强。
  • setContentCompressionResistancePriority:: 优先级越高,代表拉伸越厉害,越晚被压缩。就是上图那人推的力量更强

作者:天空中的球
链接:https://www.jianshu.com/p/89bb8a1888c8
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

 
个人实例:
 
//左侧输入框右侧按钮按钮变长有限制最小宽度,保持输入框与按钮左侧距离,设定按钮的压缩性强(即一般不被拉伸)输入框拉伸性强容易拉伸
[self.Button mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.TextField);
make.right.equalTo(contentView).offset(-DWF());
make.height.mas_equalTo();
make.width.mas_greaterThanOrEqualTo(DWF());
}]; [self.Button setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal]; [self.TextField mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(DWF());
make.left.equalTo(self.verifyTipLabel);
make.top.equalTo(self.verifyTipLabel.mas_bottom).offset(DEVICE_HEIGHT_OF(YDMargin20));
make.right.mas_equalTo(self.Button.mas_left).offset(-DWF());
}]; [self.TextField setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
 
图示:
 

masonry布局说明-LMLPHP

05-11 17:06