NSLayoutConstraint
(in iOS 8.0
) has a BOOL
property called active
which makes it easy to disable/enable said layout constraint on-the-fly.
To create a second layout set for a view controller which I can then programmatically enable/disable (via an IBOutletCollection
of NSLayoutConstraints
for both sets) , I'll need to disable my already defined layout constraints in interface builder.
Let me clear here I do NOT want to delete them, just disable them so that i can design a second set without interface builder complaining all the time about mismatching constraints. Furthermore switching size classes is not an option, since the layout sets are meant for one and the same size class.
Is there an option to do so?
Thanks in Advance
Malte
Further Information: SDK Version: 8.1
Deployment Target 8.0
Select the constraint you want to disable in storyboard, and Option+Command+4 to show Attributes Inspector, then unselect Installed.
I'd previously used the solution provided by Gabbler successfully, but recently I tried the same thing using Swift 2.0 and Xcode 7 and found that it no longer worked. Constraints that were set as not installed were, as one might expect, not installed at all and had no effect on the layout when switched on or off.
My solution to the problem was to ensure that all constraints were Installed and to add a user-defined runtime attribute with the key 'active', type 'boolean' and value 'false'.
The user-defined runtime attribute panel can be found in the Identity Inspector underneath the Custom Class fields.
My solution using Xcode 8 and Swift 3 without getting any warnings was unchecked the Installed box on Interface builder, Inspector tab:
Then create the IBOutlets and add/remove them programmatically on viewDidLayoutSubviews()
view.removeConstraints([constraints to remove, ...])
view.addConstraints([constraints to add, ...])
Make sure to remove the constraints first, otherwise you will get the message log Unable to simultaneously satisfy constraints...
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