Undeleteable constraints added by InterfaceBuilder
Asked Answered
C

3

11

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.

Cyndicyndia answered 14/10, 2016 at 17:53 Comment(0)
B
3

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.

Buckling answered 15/12, 2016 at 15:44 Comment(0)
H
2

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

Hammy answered 5/11, 2019 at 18:30 Comment(0)
O
0

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.

Outflank answered 3/11, 2016 at 6:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.