美文网首页
纯代码约束

纯代码约束

作者: 彧哥哥 | 来源:发表于2021-08-06 15:16 被阅读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)
    

    相关文章

      网友评论

          本文标题:纯代码约束

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