Skip to content

Instantly share code, notes, and snippets.

@jeantimex
Created October 2, 2016 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeantimex/b740aefcfdc39a243536fc79cb80cae1 to your computer and use it in GitHub Desktop.
Save jeantimex/b740aefcfdc39a243536fc79cb80cae1 to your computer and use it in GitHub Desktop.
Autolayout
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