Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

enter image description here

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

like image 363
LuckyLuke Avatar asked Dec 30 '15 22:12

LuckyLuke


People also ask

How does UIStackView layout elements in a stack?

The stack view aligns the first and last arranged view with its edges along the stack's axis. In a horizontal stack, this means the first arranged view's leading edge is pinned to the stack's leading edge, and the last arranged view's trailing edge is pinned to the stack's trailing edge.

What's a UIStackView did you use it?

UIStackView is useful when you need to repeat same views multiple times like in Sing up view. We use many textfields and manually set constraints between each textfields. But if you put all textfields in stack view then you just need to set required constraints of stackview only and not textfields.

How do you add constraints in stack view?

Select the stack view that you just created. Click the Align button in the layout bar. Check the Horizontally in Container option and click Add 1 Constraint. Next, to add a spacing constraint, click the Add New Constraints button and set the value of the bottom side to 30 .


1 Answers

  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

like image 178
Sofeda Avatar answered Oct 23 '22 06:10

Sofeda