Created
November 20, 2016 13:39
-
-
Save tdkn/97f11e23dff03586b933c93e4d9b422f to your computer and use it in GitHub Desktop.
Sample of NSLayoutConstraint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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