XCode: How to find all then delete all disable constraints - 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

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.

Disable constraints are generated when you create a constraint and delete it from under "Size inspector (one with ruler like)". Just remember to delete it from your scene, then you will not have disable constraint floating around...or just delete it when u see it :).

#Dace Wood and #Bao Tran already said some useful measures. I would like to add something.
If these disabled constraints are only for a specific view object, you can manually delete those disabled constraints from IB and then add new ones. Or to take risk, you can use the "Reset to suggested Constraints" or "Add Missing Constraints" seen in "Resolve Auto Layout issues" seen in bottom right part of storyboard. It is really helpful.

Related

deleting a constraint in storyboard makes it gray (disabled) - I want to delete it

I'm in my storyboard, and applied a constraint by control-dragging from one view to another, to replace another constraint that doesn't make sense anymore. So I select the view, go to the "Size Inpector", hit the old constraint, and then the delete key.
The annoying thing, is that it just clears the "Enabled" flag, and grays out the constraint.
And yes, I am using size-classes... but here's the thing, I don't have this constraint used on any other size classes. In fact, currently there are no variants of views, constraints, etc. Everything is on "Any / Any".
So, I'm wondering if there's a way to make the Delete key actually work here. Is my only recourse going to the Document Outline, and finding my constraint in there? It just seems like there should be a more simple way to ditch the constraint, but in the Size Inspector.
If you're using size classes what often happens is that when you delete a constraint, it merely removes it for that size class.
However, there is a clear visual hint given when you do this: the constraint icon goes grey and is easily identifiable in the document outline, from where it can be selected and removed completely.
I'm not sure whether this has changed over various versions of XCode, but I find when I select it in the inspector, it does not remove it unless you are on Any/Any.

Xcode Constraints

I'm having a problem with Xcode constraints. I'm laying out my entire layout, then selecting all the items and having Xcode 'fill in missing constraints'. Now when I run the application in the simulator, labels and textboxes are NOT in the right places. Sometimes not visible at all (appear to be off screen)
So are there any tips or tricks? Should I layout 1 item at a time, set the constraints automatically then move to the next?
Don't trust XCode and 'fill in missing constraints' feature. The best option is to set all constraints manually. After some practice it's not that hard. You need to indicate X and Y coordinates and sometimes height/weight.
I really don't advice setting constraints automatically. It usually causes more problems than benefits.
Also check the console log at runtime. It may happen that there are conflicts between constraints and you need to fix it.
Check out the official guidlines

How to disable "Relative to margin" option for newly created constraint in Xcode6

I want to disable automatic adding Relative to margin when creating constraints in IB of Xcode 6.
It's nice that they turn this option on by default, but I have to support iOS7, so it turned out I have to manually disable this option every time after adding new constraint.
I found this setting for disabling it beforehand, but it's always on by default.
The closest I've ever come to this is hacky at best, so take this for what it is...
Creating AL constraint while not holding Option:
Creating AL constraint while holding option:
In IB if you hold Option while creating the AL constraint, it toggles whether the constraint binds to a margin or not. That's one convenient way to avoid re-editing the constraint. Further (and this is the hacky part because I can't explain it) I've noticed that in projects where I start holding option and binding AL constraints without the margin, that behavior becomes the default!
Like I said, it's hacky and I can't explain it why the default changes sometimes, but holding Option when you create constraints is the closest I've ever gotten.
This plugin will set a default value of Constrain to margins to disabled.
https://github.com/mshibanami/DefaultMarginDisabler
It is by default enabled in storyboards, I have not found how to disable it.
But in Xibs, it is unchecked when you create a constraint.
A solution may be to create a storyboard that instantiates your xibs, but you will loose every possibilities given by the segues.
So You may want to deal with it since there's no option for that (so far... ?).

Attribute Unavailable warning on iOS versions prior to 8.0

What's causing this warning in the interface builder?
Attribute Unavailable
Layout attributes relative to the layout margin on iOS versions prior to 8.0.
I'm using the XCode 6 Beta. The warnings are pointing to lines in the xml source that do not concern attributes.
Since I had already created the constraints, the answer was to click on the constraint, and then look in the Utilities bar (on the right). As shown in the picture below, click on an item and then make sure that "relative to margin" is unchecked.
When you add constraints in Xcode 6, you have the option "Constrain to margins" which create a different constraint and can't be read, for example, in Xcode 5.
Create the constraints without this options and the warnings should go away. This constraints will be available on iOS 8.
If you have already created the constraints, we can change it clicking on the constraint and editing it. When selecting the second item, you can uncheck the "Relative to margin" option (as explained in the GLee answer.
If you can't find where the warning is coming from you can use this grep to find it.
Run this in Terminal in your project directory:
grep -C 6 -nr Margin .
The 6 says how many lines of context to show before and after the match.
As per Gasper Kolenc opening the storyboard as Source Code is very useful. Here is a bit more info from my experience fixing this problem:
In the storyboard source code search for "margin".You will see a line such as this.
constraint firstAttribute="trailingMargin" secondItem="Pgb-8w-IHT" secondAttribute="trailing" constant="8" id="nKP-uZ-7Xm"/
Find the id of one of the attributes (Pgb-8w-IHT in the example above).
Scroll up to find in which object this constraint belongs. Something like:
tableViewCell contentMode="scaleToFill" selectionStyle="default"
Switch back to storyboard view and show the identity inspector window.
Search through the subviews of the object you found above to find the id (Pgb-8w-IHT) on the identity inspector.
Once found inspect the constraints to find the one that needs to be deleted and recreated without the constrain to margins option selected (use the constant=" " as a hint".
In my case, I had to uncheck the "Use Auto Layout" from my storyboard in the File Inspector, and redo all the constraints in my app, the old way with that shrinking / enlarging red rectangle.
Size Classes were already disabled and the target is IOS 7.1.
But think well if you have too many View Controllers, and had already made all your constraints. When you disable auto layout, Xcode clears all the automatic constraints and reverts to the old model. Then you have to do all the job again.
This was the only way I get rid of that Attribute Unavailable warning.

Missing Constraint Autolayout Warning

I have a project and I used to add constraints with xcode interface builder. In a specific case I needed to add some constraints in my controllers source. My question is that although I have the result I was seeking for, xcode returns missing constraints warnings.
Is this something I should handle? I mean, I add constraints in the source code. Show I do something to update my storyboard in order to be aware of these?
You don't need to handle these, but if you want to get rid of the warnings, you can add placeholder constraints in IB, that are removed at build time, so you can replace them with code generated constraints. When you select a constraint, and go to the Attributes Inspector, you will see a box, "Placeholder -- Remove at build time". If you check that box, those constraints are automatically removed.
No,you dont need to , if you have added constraints in the source code than it will be executed during runtime. so you dont need to handle those warning only if you have added those constraints in the source code.
AutoLayout is a descriptive "language" which describes how the layout should be rendered (frames size, spacing etc.) into the view during the runtime. When you have missing constraints warning, in other words ambiguous layout,there is a good chance that the layout will have unpredictable behavior. In order to make sure that your layout is rendered as you wish, you should clear these warnings.

Resources