美文网首页
UIScrollView 自动布局 contentSize 自适

UIScrollView 自动布局 contentSize 自适

作者: 小白lf | 来源:发表于2021-04-02 12:01 被阅读0次
        let scroll = UIScrollView().then {
            $0.backgroundColor = .red
        }
        view.addSubview(scroll)
        scroll.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        let container = UIView().then {
            $0.backgroundColor = .orange
        }
        scroll.addSubview(container)
        container.snp.makeConstraints { make in
            make.edges.equalToSuperview()
            make.width.equalToSuperview()
        }
       
        let subview1 = UIView()
        container.addSubview(subview1)
        subview1.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(20)
            make.trailing.equalToSuperview().offset(-20)
            make.top.equalToSuperview()
            make.height.equalTo(120)
            // 这行代码 不能少
            make.bottom.equalToSuperview().offset(-20)
        }

相关文章

网友评论

      本文标题:UIScrollView 自动布局 contentSize 自适

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