I have an array of buttons which I have added within a stackview, I need to add this stackView in one of my subview which is in another parentStackView. This is my code:
let innerStackView = UIStackView(arrangedSubviews: buttonViews(withTitleArray: buttonTitleArray, numberArray: ButtonTagArray))
innerStackView.backgroundColor = UIColor.green
innerStackView.axis = .vertical
innerStackView.distribution = .fillEqually
innerStackView.alignment = .fill
innerStackView.spacing = 5
innerStackView.translatesAutoresizingMaskIntoConstraints = false
mainView.bottomView.backgroundColor = UIColor.red
mainView.bottomView.addSubview(innerStackView)
NSLayoutConstraint.activate([
mainView.leadingAnchor.constraint(equalTo: innerStackView.leadingAnchor),
mainView.trailingAnchor.constraint(equalTo: innerStackView.trailingAnchor),
mainView.widthAnchor.constraint(equalTo: innerStackView.widthAnchor),
mainView.heightAnchor.constraint(equalTo: innerStackView.heightAnchor)])
mainView.alpha = 1
mainView.clipsToBounds = true
parentstackView.addArrangedSubview(mainView)
self.view.layoutIfNeeded()
The issue is that even though I can see the mainView in my parentStackView, the inner stackview is not visible. I can't seem to understand why?
Any help would be appreciated.