Chameleon
Chameleon

Reputation: 1608

Is it possible to delete/create a constraint

screenshot of constraints

I want to learn if there's a way to delete AND create a constraint

So I have greenTop constrained to viewTop, purpleTop to greenBottom etc...

I want to be able to delete greenTop-viewTop constraint, delete purpleTop-greenBottom...and create a new purpleTop-viewTop constraint and a greenTop-blackBottom. (programmatically)

Effectively moving green to bottom and all others shift up one space.

Note: I know i could just make each constrained to topView and adjust, but I'd like to learn this way.

Upvotes: 0

Views: 51

Answers (1)

rdelmar
rdelmar

Reputation: 104082

Sure, you can do that. You can make an IBOutlet to a constraint just like any other object. Call removeConstraint on the owner of that constraint to remove it,

someView.removeConstraint(someConstraint) // someConstraint is an IBOutlet

You cannot change the items or a relationship in a constraint, so #2 will not work.

Upvotes: 1

Related Questions