1

I have 2 views inside a vertical stackview(bothalf and tophalf). Their constraints dependent on that stackview.I have a horizontal stackview(containerStackView3) inside the botHalfView. Its constraints leading,trailing and height dependent on botHalfView. In debugging window i can see also on console, height of the bothalfview.frame.height=0 which i added as a constraint for horizontalstackview. Therefore horizontalstackview inside the bothalfview not showing any dimension. To which constraint i should assign the horizontalstackview's height? Or any other solution to this?

       let containerStackView3 = UIStackView()
        containerStackView3.translatesAutoresizingMaskIntoConstraints = false
        containerStackView3.axis = .vertical
        containerStackView3.distribution = .fillEqually
        containerStackView3.spacing = 1
 //adding views
        containerStackView1.addArrangedSubview(botHalfView2)
        botHalfView2.addSubview(containerStackView3)

//constraints bothalfview 
        botHalfView2.bottomAnchor.constraint(equalTo: 
        containerStackView1.bottomAnchor, constant: 0).isActive = true
        botHalfView2.leadingAnchor.constraint(equalTo: 
        containerStackView1.leadingAnchor, constant: 0).isActive = true
        botHalfView2.trailingAnchor.constraint(equalTo: 
        containerStackView1.trailingAnchor, constant: 0).isActive = true

// Constraints of the stack view inside the bothalfview
        containerStackView3.leadingAnchor.constraint(equalTo: 
        botHalfView2.leadingAnchor, constant: 0).isActive = true
        containerStackView3.trailingAnchor.constraint(equalTo: 
        botHalfView2.trailingAnchor, constant: 0).isActive = true
        containerStackView3.bottomAnchor.constraint(equalTo: 
        botHalfView2.bottomAnchor, constant: 0).isActive = true

  containerStackView3.heightAnchor.constraint(equalToConstant:botHalfView2.frame.height).isActive = true

1 Answers1

1

If you need container heigh same as bot half then do this // Constraints of the stack view inside the bothalfview

    containerStackView3.leadingAnchor.constraint(equalTo: 
    botHalfView2.leadingAnchor, constant: 0).isActive = true
    containerStackView3.trailingAnchor.constraint(equalTo: 
    botHalfView2.trailingAnchor, constant: 0).isActive = true
    containerStackView3.bottomAnchor.constraint(equalTo: 
    botHalfView2.bottomAnchor, constant: 0).isActive = true
    containerStackView3.topAnchor(equalTo: 
    botHalfView2.topAnchor, constant: 0).isActive = true
Reed
  • 944
  • 7
  • 15