Search code examples
iosswiftxcodeautolayout

How to set trailingMargin = Stack View.trailing


I am looking at one of the Learning Io's projects and observed the constraint above in the picture. I have been trying to recreate the "Trailing Margine Space Stack View" constraints for the View on my own but have been unable to.

I have tried setting leading and trailing of stack view to zero but then this aligns the stack view to safe area view.

What I am trying to implement

I have never seen this sort of margin that appears to be generated off of the image view in the picture below. In the stack view, it appears they have "Stackview Leading : Superview". But no matter what I do I get SafeArea View.

enter image description here


Solution

  • When you create the constraint by control-dragging and the little HUD comes up giving you a choice of what constraint to create, hold down the Option key to see the margin choices. Click one.

    Alternatively, just create the safe area constraint and then select it and edit it. Pop up menus let you choose Superview instead of Safe Area and then you can choose Relative To Margin.