Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undeleteable constraints added by InterfaceBuilder

I'm using Xcode 8 building for iOS 9 and using auto layout.

Occasionally when I install a constraint in Interface Builder there's an immediate conflict. When I click the red disclosure and look at the conflicting constraints I'll see the one I just installed and another one that conflicts. When I click on the constraint I installed it highlights. When I click on the conflicting constraint it does not highlight. When I click the red dot to delete a constraint the check box next to the conflicting constraint is grayed out and cannot be selected. When I return to the document inspector or the size inspector I do not see the conflicting constraint listed for the object it applies to.

So it looks to me like Interface Builder adds constraints that cannot be deleted. My problem is these undeleteable constraints are not helpful. For example I add a width >= 50 constraint to a view inside of a stack view and find that it conflicts with a system-added width = 0 constraint that cannot be deleted.

Does anyone know why this is happening or how I can get around it? Thanks.

like image 502
David U Avatar asked Oct 14 '16 17:10

David U


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 I delete a constraint in Swift?

Delete a constraint: click a single constraint icon and press Delete or select Delete from the context menu.

How do I add constraints in Xib?

Select the items you want to align, and then click the Align tool. Interface Builder presents a popover view containing a number of possible alignments. Select the options for aligning the selected views, and click the Add Constraints button. Interface Builder creates the constraints needed to ensure those alignments.


2 Answers

Check to see if you are using a UIStackView. They add generated constraints, you can change some of them by adjusting it's spacing either in IB or code.

Example:

stackView.spacing = 6.0

enter image description here

like image 154
Christopher Larsen Avatar answered Oct 10 '22 08:10

Christopher Larsen


To avoid the conflict, reduce the priority of your width constraint to 250. System added constraints for UIStackView will have a priority of 1000. If you hide a view in a stack view, it will set the width (or height) constraint constant to zero.

like image 43
David Lindsay Avatar answered Oct 10 '22 08:10

David Lindsay