1

If I create a constraint in a storyboard and the Installed property is checked:

enter image description here

... I can access it by reading the constraints on my view:

myView.constraints

This will return all constraints installed at this level.

If I uncheck the Installed property in the storyboard, the constraint no longer exists in the [NSLayoutConstraint] array of myView.constraints. Is there any way I can access these uninstalled constraints in my storyboard without creating IBOutlets for them?

For example, a solution which loops over every view in the view hierarchy and finds it that way would suffice, but I can't seem to find a way to do that.

Also, if there were a myView.archivedConstraints, myView.uninstalledConstraints, or something similar, that would also be a good solution.

Senseful
  • 86,719
  • 67
  • 308
  • 465

1 Answers1

0

I think you have three ways to achieve that:

  1. Create an IBOutlet to access that constraint.
  2. Access them looping over all constraints added (not recommended)
  3. Add that constraint programatically.

but for all of them, as far as I know, you need to have that constraint installed to make it "active"/"visible"/"in the app when it run".

Maybe this post can help you activateConstraints: and deactivateConstraints: not persisting after rotation for constraints created in IB

Community
  • 1
  • 1
Gabriel Goncalves
  • 5,132
  • 3
  • 25
  • 34
  • 1
    For what I undestand, a 'not installed' constraint as nothing to do when the app runs, so it shoudn't even exist at that time... – FredericP Jul 03 '16 at 08:36
  • **1.** Yes, that would probably work, but I'm looking for another solution. **2.** I wasn't able to get this to work. If you know how to get this to work, I would accept that as a valid solution. **3.** This would also work but I explicitly want to create it in the storyboard. – Senseful Jul 03 '16 at 17:42
  • @Senseful can you call `self.superview.constraints` or specify the view you are checking. – Gabriel Goncalves Jul 03 '16 at 23:14