given the following constraint in ios programmatically:
IBOutlet NSLayoutConstraint *myConstraint;
this constraint is linked in interfacebuilder to the following details:
How do I change the relation attribute programmatically. I tried to look up for a method called setRelation but I don't see it.
According to the documentation, relation
is read-only.
What you will need to do, I suspect, is to set
self.myConstraint.active = NO;
Then make a new NSLayoutConstraint
programmatically using:
+ constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:
And in the process copying values you want to keep, and replacing the relation.
Then add it to the view hierarchy where appropriate.
You can do like that :
[self.view addConstraint:[NSLayoutConstraint
constraintWithItem:self.yellowView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:self.redView
attribute:NSLayoutAttributeWidth
multiplier:0.75
constant:0.0]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With