How to rewrite visual format
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("|-[label]-|", options: .AlignAllBaseline, metrics: nil, views: ["label": label])) addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-[label]-|", options: .AlignAllCenterX, metrics: nil, views: ["label": label]))
going to layout guides (with margins)?
I tried it with
label.topAnchor.constraintEqualToAnchor(layoutMarginsGuide.topAnchor).active = true label.leftAnchor.constraintEqualToAnchor(layoutMarginsGuide.leftAnchor).active = true label.bottomAnchor.constraintEqualToAnchor(layoutMarginsGuide.bottomAnchor).active = true label.rightAnchor.constraintEqualToAnchor(layoutMarginsGuide.rightAnchor).active = true
but does not work. Even layoutMarginsGuide.layoutFrame does not have the expected value (yes, I call it in layoutSubviews after doing super ). The limits are set, but act as a zero margin. It is a layout and gives the expected layoutFrame only when the layout is set to negative; which is clearly not what I want, but demonstrates that constraints are set using guide fields. Looks like I missed something ...
source share