美文网首页
关于tableViewCell添加修改约束的那些坑

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

作者: StonesMonkey | 来源:发表于2016-07-25 00:47 被阅读1205次

// 坑爹的玩意。在添加约束的时候或者删除的时候约束都是加到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添加修改约束的那些坑

      本文链接:https://www.haomeiwen.com/subject/vekmhttx.html