即使将autoresize设置为false,StackView也不会出现

时间:2018-11-25 18:12:21

标签: ios iphone swift

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时,视图中什么也没有。有什么我想念的吗?

enter image description here

0 个答案:

没有答案