IOS - change binding constraints programmatically

The following restriction is set in ios programmatically:

IBOutlet NSLayoutConstraint *myConstraint;

this restriction is associated in the interface with the data below: enter image description here

How to change a software attribute of a relationship. I tried to find a method called setRelation, but I do not see it.

+4
source share
2 answers

According to the documentation , relationread-only.

What you need to do, I suspect, is to install

self.myConstraint.active = NO;

Then create a new one NSLayoutConstraintprogrammatically using:

+ constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:

And in the process of copying the values ​​you want to keep, and replacing the relationship.

Then, if necessary, add it to the view hierarchy .

+8
source

You can do this:

  [self.view addConstraint:[NSLayoutConstraint
                                 constraintWithItem:self.yellowView
                                 attribute:NSLayoutAttributeWidth
                                 relatedBy:NSLayoutRelationEqual
                                 toItem:self.redView
                                 attribute:NSLayoutAttributeWidth
                                 multiplier:0.75
                                 constant:0.0]];
0
source

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


All Articles