How to change auto layout constraints after adding

I know that to change layout constraints using IBOutlet NSLayoutConstraint * xyz;

I am doing with this code:

Add using this code

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

Get using 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 view constraints then arrConstarint.count is 0, please help me where I am wrong. Thanks in advance.

+5
source share
1 answer

Try

 [supperView addConstraint:btnbottomConstraint]; 

to

 [currentView addConstraint:btnbottomConstraint]; 

height and width will not be added for viewing in relation to the supervisor. Let me know if you need more help.

+2
source

Source: https://habr.com/ru/post/1208485/


All Articles