Skip to content

Instantly share code, notes, and snippets.

@tdkn
Created November 20, 2016 13:39
Show Gist options
  • Save tdkn/97f11e23dff03586b933c93e4d9b422f to your computer and use it in GitHub Desktop.
Save tdkn/97f11e23dff03586b933c93e4d9b422f to your computer and use it in GitHub Desktop.
Sample of NSLayoutConstraint
label.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(label)
view.addConstraints([
NSLayoutConstraint(
item: label,
attribute: .width,
relatedBy: .equal,
toItem: nil,
attribute: .width,
multiplier: 1.0,
constant: 100
),
NSLayoutConstraint(
item: label,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .height,
multiplier: 1.0,
constant: 100
),
NSLayoutConstraint(
item: label,
attribute: .centerX,
relatedBy: .equal,
toItem: view,
attribute: .centerX,
multiplier: 1.0,
constant: 0.0
),
NSLayoutConstraint(
item: label,
attribute: .centerY,
relatedBy: .equal,
toItem: view,
attribute: .centerY,
multiplier: 1.0,
constant: 0.0
),
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment