override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
setupLabels()
}
fileprivate func setupLabels() {
let greenView = UIView()
greenView.backgroundColor = .green
let stackView = UIStackView(arrangedSubviews: [greenView])
stackView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(stackView)
NSLayoutConstraint.activate([
stackView.topAnchor.constraint(equalTo: view.topAnchor, constant: 40),
stackView.bottomAnchor.constraint(equalTo: view.topAnchor, constant: 40),
stackView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 40),
stackView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 40)
])
}
我的stackview没有出现。我以为它可能隐藏在VC视图的后面,但是当我将颜色设置为clear时,视图中什么也没有。有什么我想念的吗?