Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode: How to find all then delete all disable constraints

Tags:

xcode

ios

I am new in iOS. I see a lot of disable constraints in my Main.storyboard and I want to delete it. However, my Main.storyboard have many screen so I want to find the way to find all disable constraints then delete all.
Is it possible with Xcode?
Or any way to prevent disable constraint generate.
Any help would be great appreciate

enter image description here

like image 951
Linh Avatar asked Mar 29 '16 03:03

Linh


People also ask

How do I delete all constraints in XCode?

To remove constraints for a single view you select the view and hit the triangle button in the bottom right hand corner... And hit "Clear Constraints" under the "Selected Views" part. To clear constraints for an entire View Controller do the same but hit "Clear Constraints" under the "All Views in ..." part.

How do you add constraints in XCode?

To create constraints select the button and click the Align icon in the auto layout menu. A popover menu will appear, check both “Horizontal in container” and “Vertically in container” options to center the button on the screen. Then click the “Add 2 Constraints” button. Run the application.


1 Answers

Obviously there's the manual way, of going through all of the constraints in Interface Builder and just deleting the disabled ones.

But, if you have a tonne of disabled ones and you just want to wipe them all out, you can edit the storyboard file directly (do this with Xcode closed).

You could build a script to this, but here's the manual process to start with.

Look in the Storyboard file for lines such as: <exclude reference="egm-9S-fZb"/> In this case, egm-9S-fZb is the id of the constraint that's disabled. Now find a line in the storyboard like this: <constraint ... id="egm-9S-fZb"/>

Delete both of those lines and you've deleted that disabled constraint.

Note: Be aware that if you have constraints that are disabled in certain conditions, i.e., you have a constraint that's only enabled for say Compact Width, Compact Height, it will be listed with an exclude line, as well as an include line. So check for an include line before deleting the exclude and the constraint lines.

like image 118
Dave Wood Avatar answered Oct 04 '22 11:10

Dave Wood