方式一 遍历 找到xib中的约束 修改
for(NSLayoutConstraint *constraint in self.constraints)
{
if (constraint.firstItem==self && constraint.firstAttribute== NSLayoutAttributeLeading) {
constraint.constant=100;
}
}
方式二 全删除 重新添加
[self removeConstraints:self.constraints];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.merchantYHL attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeading multiplier:1 constant:10]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:70]];
另 :一启动就修改 在view的
-(void)updateConstraints 中修改约束 controller是在updateViewConstraints中修改