UIScrollView 自动布局 contentSize 自适
2021-04-02 本文已影响0人
小白lf
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)
}