按照以前的方法添加约束后报错
需要往scrollView添加一个ContainerView或者View,设置该View的约束(四边=0)
鼠标指到Content Layout Guide,按住右键拖到ContainerView,松手选中前两项就好
这里报错就消失了,用代码向ScrollView中添加一个label看看布局是否正确,以及约束是否生效
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
let label = UILabel(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
label.text = "test"
label.backgroundColor = UIColor.red
scrollView.addSubview(label)
}
}