How to remove constraints programmatically that is added from storyboard?

Dharmik picture Dharmik · Dec 31, 2014 · Viewed 81k times · Source

I have googled but not find out answer. So I need to ask. I have one home screen. When User is logged in it will display one view as like bellow enter image description here Now When User logged out and visiting home page he will see above layout but without center boxed layout. If I set That layout hidden it is now displaying as follows. enter image description here

I want to move third layout to little bit above to remove white space..

I added constraints using storyboard. Now need to remove constraints from programming and add one constraints that will set layout to bellow first layout..

Answer

Mrunal picture Mrunal · Dec 31, 2014

As @Henit mentioned, you can set IBOutlet for constraints as well.

For example,

@property(weak, nonatomic) IBOutlet NSLayoutConstraint *viewHeight;

so now, you can remove this constraint like this:

[myView removeConstraint: viewHeight];

Or else if you want to remove all / multiple constraints related to your view then,

[myView removeConstraints: constraintsArrayHere]; // custom array of constraints references
[myView removeConstraints: [myView constraints]]; //all constraints

Then later you can add your new constraints in the same manner using addConstraint or addConstraints method.

For more details go through Apple Documentation here.

Hope this helps.