Created
October 2, 2016 02:00
-
-
Save jeantimex/b740aefcfdc39a243536fc79cb80cae1 to your computer and use it in GitHub Desktop.
Autolayout
This file contains 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
override init(reuseIdentifier: String?) { | |
... | |
// arrowLabel must have fixed width and height | |
arrowLabel.widthAnchor.constraintEqualToConstant(12).active = true | |
arrowLabel.heightAnchor.constraintEqualToConstant(12).active = true | |
titleLabel.translatesAutoresizingMaskIntoConstraints = false | |
arrowLabel.translatesAutoresizingMaskIntoConstraints = false | |
} | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
... | |
let views = [ | |
"titleLabel" : titleLabel, | |
"arrowLabel" : arrowLabel, | |
] | |
contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat( | |
"H:|-20-[titleLabel]-[arrowLabel]-20-|", | |
options: [], | |
metrics: nil, | |
views: views | |
)) | |
contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat( | |
"V:|-[titleLabel]-|", | |
options: [], | |
metrics: nil, | |
views: views | |
)) | |
contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat( | |
"V:|-[arrowLabel]-|", | |
options: [], | |
metrics: nil, | |
views: views | |
)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment