swift UIView中嵌入UIScrollview滚动
![](https://img.haomeiwen.com/i5263054/f1bb4e338d391f43.png)
image.png
class ViewController: UIViewController {
var scroll:UIScrollView?
override func viewDidLoad() {
super.viewDidLoad()
let root = UIView.init(frame: CGRect.init(x: 0, y: 300, width: self.view.bounds.width, height: 200))
root.backgroundColor = .gray
scroll = UIScrollView.init(frame: root.bounds)
for i in 0...10 {
let lab = UILabel.init(frame: CGRect.init(x: 0, y: 100 * i, width: Int(self.view.bounds.width), height: 100))
lab.text = "lab\(i)"
scroll?.addSubview(lab)
}
scroll?.contentSize = CGSize.init(width: self.view.bounds.size.width, height: 100 * 11)
root.addSubview(scroll!)
self.view.addSubview(root)
}
}
本文标题:swift UIView中嵌入UIScrollview滚动
本文链接:https://www.haomeiwen.com/subject/pbbkqctx.html
网友评论