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)
}
}
网友评论