纯代码约束
2021-08-06 本文已影响0人
彧哥哥
方法一
import SnapKit
colltionView!.snp.makeConstraints { (make) in
make.top.equalTo(0)
make.bottom.equalTo(0)
make.left.equalTo(0)
make.right.equalTo(0)
}
https://www.jianshu.com/p/b61b93cde38a
方法二
colltionView!.translatesAutoresizingMaskIntoConstraints = false
let top:NSLayoutConstraint = NSLayoutConstraint(item: colltionView!, attribute: NSLayoutConstraint.Attribute.top , relatedBy:NSLayoutConstraint.Relation.equal, toItem:self.view, attribute:NSLayoutConstraint.Attribute.top, multiplier:1.0, constant: 0)
colltionView!.superview!.addConstraint(top)
let bottom:NSLayoutConstraint = NSLayoutConstraint(item: colltionView!, attribute: NSLayoutConstraint.Attribute.bottom , relatedBy:NSLayoutConstraint.Relation.equal, toItem:self.view, attribute:NSLayoutConstraint.Attribute.bottom, multiplier:1.0, constant: 0)
colltionView!.superview!.addConstraint(bottom)
let left:NSLayoutConstraint = NSLayoutConstraint(item: colltionView!, attribute: NSLayoutConstraint.Attribute.left , relatedBy:NSLayoutConstraint.Relation.equal, toItem:self.view, attribute:NSLayoutConstraint.Attribute.left, multiplier:1.0, constant: 0)
colltionView!.superview!.addConstraint(left)
let right:NSLayoutConstraint = NSLayoutConstraint(item: colltionView!, attribute: NSLayoutConstraint.Attribute.right , relatedBy:NSLayoutConstraint.Relation.equal, toItem:self.view, attribute:NSLayoutConstraint.Attribute.right, multiplier:1.0, constant: 0)
colltionView!.superview!.addConstraint(right)