简体   繁体   English

添加后如何更改自动布局约束

[英]how to change auto layout constraints after add

I know to change auto layout constraints with IBOutlet NSLayoutConstraint * xyz; 我知道用IBOutlet NSLayoutConstraint * xyz;改变自动布局约束IBOutlet NSLayoutConstraint * xyz;

I am doing with this code: 我正在使用此代码:

Add constraints with this code 使用此代码添加约束

NSLayoutConstraint *btnbottomConstraint = [NSLayoutConstraint constraintWithItem: currentview attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1.0f constant:sheight];
        [supperView addConstraint:btnbottomConstraint];

Get constraints with this code 使用此代码获取约束

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;
    }
}

when i get constraints of view then arrConstarint.count is 0, please help me where i wrong.Thanks in advance. 当我得到视图的约束然后arrConstarint.count是0,请帮助我在哪里我错了。谢谢提前。

Try 尝试

[supperView addConstraint:btnbottomConstraint];

to

[currentView addConstraint:btnbottomConstraint];

height and width will be added to view not with respect to superview. 将添加高度和宽度以查看与superview无关。 Let me know if it you need further help 如果您需要进一步的帮助,请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM