问题
When we add constraints, we have the choice between "Align" button in the auto layout toolbar or "Pin" button.
In my storyboard, if I add a new alignment constraint "Bottom edges" between a scrollview and his container.

The icon of this constraint is 2 squares and a line.
But after, in the list of constraints of my scrollview, the icon is different :

The icon is a "Pin" icon.
I don't understand why.
One more question, I think it's related : what is the difference between "Align bottom" and "Bottom space" ?
回答1:
Pin and Align are just abstractions to make it easier to understand what you are setting up. In reality, a constraint is a relation between attributes of two objects. What you specify in Interface Builder with align or pin gets translated into an NSLayoutConstraint
object.
When done programmatically, there is no pin or align option, you are just specifying the objects, their attributes (.Top
, .Bottom
, .CenterX
, etc.) , the relation (.Equal
, .GreaterThanOrEqual
, .LessThanOrEqual
), a constant, and a multiplier.
For example, here is how to align the bottoms of two buttons:
NSLayoutConstraint(item: button1, attribute: .Bottom, relatedBy: .Equal, toItem: button2, attribute: .Bottom, multiplier: 1.0, constant: 0.0)
If the two objects are siblings, then their bottoms are considered to be aligned. If one object is a subview of the other object, then it is considered to be Bottom Space. Both are just a relation between the .Bottom
of one view to the .Bottom
of the other view.
When you click on the constraint and view it in the Attributes Inspector, you see the values that are used to create the NSLayoutConstraint
.

来源:https://stackoverflow.com/questions/27892626/i-add-a-align-constraint-but-xcode-add-a-pin-constraint-autolayout