masory一行两个label设置优先级

创建label的category
.h声明
//优先左 以左为基准 左边约束大于右边
-(void)leftGreaterThanOrEqualToRight:(UILabel *)rightLabel offset:(CGFloat)offset;
//优先右 以右为基准 右边约束大于左边
-(void)leftlessThanOrEqualToRight:(UILabel *)rightLabel offset:(CGFloat)offset;

.m实现
-(void)leftGreaterThanOrEqualToRight:(UILabel *)rightLabel offset:(CGFloat)offset{
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.greaterThanOrEqualTo(rightLabel).offset(-offset);
}];
[rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.lessThanOrEqualTo(self.mas_right).offset(offset);
}];
[self setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[rightLabel setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];

}
-(void)leftlessThanOrEqualToRight:(UILabel *)rightLabel offset:(CGFloat)offset{
[rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.greaterThanOrEqualTo(self.mas_right).offset(offset);
}];
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.lessThanOrEqualTo(rightLabel.mas_left).offset(-offset);
}];
[rightLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[self setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];

}

你可能感兴趣的:(masory一行两个label设置优先级)