Why won't constraint to margins work in Xcode 9?

When I wanted to add constraints to a stack view, I wanted it to constraint to margins. I checked the box off, but it would not work. Please help (Using Xcode 9).

Accepted Reply

I was having the same problem and recently resolved the issue by turning off the safe area. Safe Area Layout is enabled by default. To disable Safe Area Layout in Xcode 9, choose View > Utilities > Show File Inspector and deselect the checkbox for Use Safe Area Layout Guides. This should correct the issue. Good luck, hope it helps.

Replies

It seems like its because of the "safe area" added for the iPhone X. After a lot of frustration I was able to overcome that by adding a view that snap to the side of the screen, that gave me the margins to work with.

I am facing the same issue. Were you able to find any workaround?

The workaround I found is that you can tkae a regular UIView and set it to 0 from each edge, the use that as your main view. That way you can get the margins from that view

I was having the same problem and recently resolved the issue by turning off the safe area. Safe Area Layout is enabled by default. To disable Safe Area Layout in Xcode 9, choose View > Utilities > Show File Inspector and deselect the checkbox for Use Safe Area Layout Guides. This should correct the issue. Good luck, hope it helps.