![](/img/trans.png)
[英]How to change Auto Layout constraints after they are set when using constraintEqualToAnchor()?
[英]how to change auto layout constraints after add
我知道用IBOutlet NSLayoutConstraint * xyz;
改变自动布局约束IBOutlet NSLayoutConstraint * xyz;
我正在使用此代码:
使用此代码添加约束
NSLayoutConstraint *btnbottomConstraint = [NSLayoutConstraint constraintWithItem: currentview attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1.0f constant:sheight];
[supperView addConstraint:btnbottomConstraint];
使用此代码获取约束
NSArray * arrConstarint=btnSubbmit.constraints;
for (NSLayoutConstraint * constraint in arrConstarint)
{
if (constraint.firstAttribute==NSLayoutAttributeHeight)
{
constraint.constant=self.maxHeight;
}
else if (constraint.firstAttribute==NSLayoutAttributeWidth)
{
constraint.constant=self.maxWidth;
}
}
当我得到视图的约束然后arrConstarint.count是0,请帮助我在哪里我错了。谢谢提前。
尝试
[supperView addConstraint:btnbottomConstraint];
至
[currentView addConstraint:btnbottomConstraint];
将添加高度和宽度以查看与superview无关。 如果您需要进一步的帮助,请告诉我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.