Created
March 13, 2015 18:41
-
-
Save danielgomezrico/7ab4c841e013fdfe62b4 to your computer and use it in GitHub Desktop.
Autolayout For UITableView
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
class SelectableCell: UITableViewCell { | |
override func awakeFromNib() { | |
super.awakeFromNib() | |
if let myconstraints = constraints() as? [NSLayoutConstraint] { | |
for cellConstraint: NSLayoutConstraint in myconstraints { | |
removeConstraint(cellConstraint) | |
if let firstItem = (cellConstraint.firstItem === self) ? contentView : cellConstraint.firstItem as? UIView, | |
seccondItem = (cellConstraint.secondItem === self) ? contentView : cellConstraint.secondItem as? UIView { | |
let contentViewConstraint = NSLayoutConstraint(item: firstItem, | |
attribute: cellConstraint.firstAttribute, | |
relatedBy: cellConstraint.relation, | |
toItem: seccondItem, | |
attribute: cellConstraint.secondAttribute, | |
multiplier: cellConstraint.multiplier, | |
constant: cellConstraint.constant) | |
contentView.addConstraint(contentViewConstraint) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment