The view's left margin size is view.layoutMargins.left
.
You can get a layout anchor for the left margin as view.layoutMarginsGuide.leftAnchor
. Example:
subview.leftAnchor.constraintEqualToAnchor(view.layoutMargins.leftAnchor).active = true
Note though that if you want your interface to flip correctly in a right-to-left locale, you should use leadingAnchor
:
subview.leadingAnchor.constraintEqualToAnchor(view.layoutMargins.leadingAnchor).active = true
If you want to create a layout constraint using the old NSLayoutConstraint.
init(item:attribute:relatedBy:toItem:attribute:multiplier:constant:)
constructor, the attributes are named .LeftMargin
and .LeadingMargin
.