13

My wish is to have a UIStackView added in the Storyboard with 0 height that I reference in the code to add subviews to programatically. However, Storyboard is complaining about that it doesn't have a height (I haven't set it, so it is correct that it warns me). I only want it to act as a dynamic container for other views. The UIStackView I am talking about is added as a subview inside another UIStackView.

enter image description here

It is the stackview below "Name Label" it is all about.

LuckyLuke
  • 47,771
  • 85
  • 270
  • 434

2 Answers2

18
  1. Select your StackView which you want to set height 0
  2. Select Size inspector
  3. Select Intrinsic Size property of StackView
  4. Change it to Placeholder from Default
  5. Now change StackView Height as you wish!! even 0.

enter image description here

Sofeda
  • 1,361
  • 1
  • 13
  • 23
1

You can hide you inner stack view using the boolean .hidden property. Create an outlet to the inner stack view, say innerStackView, and hide it at initialization using innerStackView.hidden = true, e.g.:

@IBOutlet weak var innerStackView: UIStackView!

override func viewDidLoad() {
    super.viewDidLoad()

    // ...

    innerStackView.hidden = true
}

This will hide the stack view even if it contains several other views; hence, it can act as your hidden dynamic container, and you needn't fiddle around with height properties. If you want to show the view again, simply bitswap the .hidden property to innerStackView.hidden = false.

dfrib
  • 70,367
  • 12
  • 127
  • 192