美文网首页
swift UIView中嵌入UIScrollview滚动

swift UIView中嵌入UIScrollview滚动

作者: wasdzy111 | 来源:发表于2020-12-28 10:04 被阅读0次
    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