简体   繁体   中英

how to change auto layout constraints after add

I know to change auto layout constraints with 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.

Try

[supperView addConstraint:btnbottomConstraint];

to

[currentView addConstraint:btnbottomConstraint];

height and width will be added to view not with respect to superview. Let me know if it you need further help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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