1

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.

Kerberos
  • 4,036
  • 3
  • 36
  • 55
Geet
  • 2,427
  • 2
  • 21
  • 39

1 Answers1

0

okay, So I couldn't find a solution programmatically, I ended up making the bottomView in the interface builder and binding it with the mainview with the help of constraints.That did the trick for me.

Geet
  • 2,427
  • 2
  • 21
  • 39