Install/Uninstall constraint programmatically

Eric picture Eric · May 28, 2015 · Viewed 12.3k times · Source

Is there a way to install and uninstall an Xcode interface builder constraint programmatically?

enter image description here

Answer

A C picture A C · May 28, 2015

Connect the IBOutlet for the NSLayoutConstraint by CTRL+click the constraint and drag it to the viewController (for ex. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraint;).

For removing the constraint:

[self.view removeConstraint:constraint]

for installing the constraint:

[self.view addConstraint:constraint]