Reputation: 12203
I'm learning autolayout. I'm currently adding a simple constraint: 0px margin between a view and it superview.
Apparently, there are two ways to add this constraint:
First, click on the lower right button of your xib editor, select the left margin and click add n constraints, as in the given screenshot:
Here's the first constrain properties. It has a 16px constant margin:
Second way, select in Xcode menu: Editor > Pin > Leading space to superview:
Now, my constraint has 0px, but it works too: the view is well adapted according to its superview
Here's my second constraint properties:
First question: why my first constraint left and right margin are 16px? I'm working on a brand new project! If I set 0px, there is some extra space around my view!
Second question: what is the difference between these two constraints? What is the best method?
Thanks
Upvotes: 0
Views: 347
Reputation: 534885
You've already given the answer. A constraint to the superview is not the same as a constraint to the superview's margin.
It might be easiest if you think about how you'd form these constraints in code. Here are the attributes you can use:
As you can see, there is both Right and RightMargin. Pinning a subview's right edge to its superview's Right is not the same as pinning it to its superview's RightMargin.
Upvotes: 1