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.
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.
Delete a constraint: click a single constraint icon and press Delete or select Delete from the context menu.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With