简体   繁体   中英

Adding UIStackView as a empty container in Storyboard

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.

在此输入图像描述

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

  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.

在此输入图像描述

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 , eg:

@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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM