Autolayout For UITableView
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)
}
}
}
}
}