内容未添加到scrollView

时间:2017-02-27 04:15:56

标签: ios swift uiscrollview

我尝试创建以下代码,其中两个方法都在viewDidLoad中调用,但是没有添加contentView。

func setupScrollView() {

    //Initialize scrollView
    scrollView = UIScrollView(frame: self.view.bounds)
    self.view.addSubview(scrollView)

    //Customize tableView
    scrollView.backgroundColor = UIColor.red

    //set contentSize
    self.scrollView.contentSize = self.view.bounds.size
    scrollView.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]

    //setup contentView
    self.contentView = UIView()
    self.scrollView.addSubview(self.contentView)

    //Customize contentView
    self.contentView.backgroundColor = UIColor.green

    self.scrollView.addSubview(self.contentView)
    self.view.addSubview(self.scrollView)

}

func setupConstraints() {



    //tableView
    contentView.snp.makeConstraints({ make in
        make.left.equalTo(0)
        make.right.equalTo(0)
        make.top.equalTo(0)
        make.bottom.equalTo(0)
    })


}

0 个答案:

没有答案