I try to set up a view with AutoLayout constraints by using constraintEqualToAnchor()
:
override func viewDidLoad() {
super.viewDidLoad()
le
Here is an example declaring a constraint c
which will be referenced later in time. We set a new constant value and then call layout
on the superview.
myView.translatesAutoresizingMaskIntoConstraints = false
var constraints: [NSLayoutConstraint] = [
myView.topAnchor.constraintEqualToAnchor(view.topAnchor),
myView.leftAnchor.constraintEqualToAnchor(view.leftAnchor),
myView.bottomAnchor.constraintEqualToAnchor(view.bottomAnchor)
]
let c = myView.rightAnchor.constraintEqualToAnchor(view.rightAnchor)
constraints.append(c)
view.addSubview(myView)
NSLayoutConstraint.activateConstraints(constraints)
// Some time later
c.constant = -100
view.setNeedsLayout()