Adding priority to layout constraints

后端 未结 1 1546
无人共我
无人共我 2021-02-07 09:47

I have a label and button in a superView like this.

|--------------[Label]-----[button]-|

I\'d like the

相关标签:
1条回答
  • 2021-02-07 10:18

    You just set the priority property of the constraint, like so:

    NSLayoutConstraint *centeringConstraint = 
        [NSLayoutConstraint constraintWithItem:_label
                                     attribute:NSLayoutAttributeCenterX
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.contentView
                                     attribute:NSLayoutAttributeCenterX
                                    multiplier:1.0
                                      constant:0.0];
    
    centeringConstraint.priority = 800; // <-- this line
    
    [self addConstraint:centeringConstraint];
    
    0 讨论(0)
提交回复
热议问题