Constrain to margin isn't working properly on Xcode
Asked Answered
S

3

17

I'm trying to set a constrain of "0" to a UIImageView from the sides (left & right) but when I add the constrain with "Constrain to margin" checked, it pins the image all the way to the edge of the ViewController while it should keep some distance, why is this happening?

Solicit answered 25/9, 2017 at 17:25 Comment(5)
Which device are you simulating on?Forewarn
I didn't try to run the simulator after adding the constraints, all of it is happening in the Interface BuilderSolicit
Having the same problem as I do the tutorial from ApplePollock
Experiencing the same on Xcode 10.2Sigrid
I also have the same problem on Xcode 11.5Gild
F
36

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.

Frobisher answered 13/10, 2017 at 6:49 Comment(2)
Wow it actually worked, this was a pain in the neck, thank you so much :DSolicit
On Xcode 11, this is in View > Inspectors > Show File Inspector, and you can also trigger it with Cmd+Option+1.Gild
G
2

Check to see if your UIImageView is overlapping or placed past that margin line. If this is the case, the constrain to margin thing doesn't do anything. What I did to fix this was manually move that object so that it was away from the margin line and try again.

This lets you keep the Safe Area.

Goren answered 22/2, 2018 at 1:47 Comment(0)
H
1

I found that if the UIView is overlapped with or by another view this issue also happens - for example if you want to put an image up by the side and you also have a full screen camera preview.

The solution for me was to drag the view where I wanted it (i.e. to one side) and then set the constraints and it behaved properly from then on - I did not have to remove the safe view. This is with Xcode 10.1.

Hydrofoil answered 4/2, 2019 at 19:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.