Skip to content

Instantly share code, notes, and snippets.

@denkeni
Last active March 27, 2017 14:50
Show Gist options
  • Save denkeni/b4630f73c009c07f7b9b083e382585a7 to your computer and use it in GitHub Desktop.
Save denkeni/b4630f73c009c07f7b9b083e382585a7 to your computer and use it in GitHub Desktop.
Auto Layout Programmatically 1-2
subviewB.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(subviewB)
constraints.append(NSLayoutConstraint(item: subviewB, attribute: .top, relatedBy: .equal,
toItem: view, attribute: .top, multiplier: 1.0, constant: 150))
// subviewA.top = 1.0 * view.top + 150
constraints.append(NSLayoutConstraint(item: subviewB, attribute: .bottom, relatedBy: .equal,
toItem: view, attribute: .bottom, multiplier: 1.0, constant: -150))
// subviewA.bottom = 1.0 * view.bottom - 150
constraints.append(NSLayoutConstraint(item: subviewB, attribute: .left, relatedBy: .equal,
toItem: view, attribute: .left, multiplier: 1.0, constant: 100))
// subviewA.left = 1.0 * view.left + 100
constraints.append(NSLayoutConstraint(item: subviewB, attribute: .right, relatedBy: .equal,
toItem: view, attribute: .right, multiplier: 1.0, constant: -100))
// subviewA.right = 1.0 * view.right - 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment