iOS UIScrollView不设置contentSize 自
2019-04-01 本文已影响0人
渴望平静生活的上班族
//创建UIScrollView
var scroView:UIScrollView= {
let scroView =UIScrollView.init()
scroView.backgroundColor = UIColor.green
return scroView
}()
//创建子view
var contentView: OrderDetailView = {
let contentView = OrderDetailView.init(frame: CGRect.zero)
return contentView
}()
scroView.addSubview(contentView)//添加父容器
contentView.snp.makeConstraints { (make) in
make.left.equalToSuperview()
make.right.equalToSuperview()
make.top.right.equalToSuperview()
make.size.equalTo(CGSize.init(width: ScreenW, height: ScreenH+50))
make.bottom.equalToSuperview()
}
重点是同时设置宽高和上下左右的约束
需要依赖自动布局框架
代码:swift <SnapKit>