关于tableViewCell添加修改约束的那些坑

// 坑爹的玩意。在添加约束的时候或者删除的时候约束都是加到contentView的cell上而不是加到cell本身上。当然删除也是删除contenView上才对@!!j

//        删除一条约束

self.contentView.removeConstraint(leftLabelConstraint)

// 创建一条Label的约束左边

self.titleLabel.translatesAutoresizingMaskIntoConstraints = false

self.imageView?.translatesAutoresizingMaskIntoConstraints = false

self.lineView.translatesAutoresizingMaskIntoConstraints = false

let newConstraint = NSLayoutConstraint(item: self.titleLabel, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: self.contentView, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 10)

self.contentView.addConstraint(newConstraint)

// 更新

self.contentView.layoutIfNeeded()

你可能感兴趣的:(关于tableViewCell添加修改约束的那些坑)