iOS Masonry 设置布局优先级。

Masonry 中设置布局优先级需要使用系统方法:

 

设置抗拉伸性。值越低越容易被拉伸

- (void)setContentHuggingPriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis;

实例代码:

    [A setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    [B setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];

由于B的抗拉伸值低,故需要拉伸时,优先拉伸B

 

设置抗压缩性。 值越低,越容易被压缩

- (void)setContentCompressionResistancePriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis

实例代码

    [A setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    [B setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];

由于B的抗压缩值低。故需要压缩时,优先压缩B

posted @ 2020-03-20 21:31  jisa  阅读(1691)  评论(0编辑  收藏  举报