1

I have a vertical stackview with 7 subviews. When I remove one of the subviews the stack view doesnt shrink, but the view above the removed view occupies the freed space.

I have tried

subview.isHidden = true

as well as

stackview.removeArrangedSubview(subview)
subview.removeFromSuperView()

Should the stackview automatically shrink by pushing all subviews below the removed subview upwards?

NataliaKh
  • 27
  • 7

1 Answers1

5

No it won't shrink , but when you set

subview.isHidden = true

the other views occupy the freed space if you set distribution to fillEqually , if you want it to shrink then hook the height constraint of it and in addition to the above line do

stackH.constant = numberOfRemainingSubviews * viewHeight
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
  • sorry to bother I've created this chatroom [here](https://chat.stackoverflow.com/rooms/177811/stackview-discussion). Can you jump in? – mfaani Aug 10 '18 at 13:46