David U
David U

Reputation: 993

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.

Upvotes: 11

Views: 1694

Answers (3)

Christopher Larsen
Christopher Larsen

Reputation: 1411

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

Upvotes: 2

David Lindsay
David Lindsay

Reputation: 220

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.

Upvotes: 3

Gowry
Gowry

Reputation: 11

Check whether the conflicting constraint is added in any other size class. It can happen that the constraint is enabled only in that size class and disabled for the size class you are currently working on.

Upvotes: 0

Related Questions