Leem.fin
Leem.fin

Reputation: 42662

Resize Stack View

I have a UILabel and a Switch on storyboard, I use Stack View to group them, however,after embedded into a horizontal Stack View, I am not able to resize the stack view but only can move it around. Why?

(I am using XCode 8 + Swift 3)

enter image description here

===== UPDATE ======

Thanks guys suggesting for adding constraints, but .... I added constraints, but I still would like to see the constrainted layout on storyboard instead of messed up layout.

E.g. I added constraint to leading and trailing space to be 8 pixel away from parent, but I see red line which xcode gives to indicate the actual layout is not showing in the constraint way. That's the problem, I can only drag the stack view, but I want to resize it to match my constraint so that it looks same as that in real device.

Upvotes: 3

Views: 17530

Answers (3)

yogesh wadhwa
yogesh wadhwa

Reputation: 721

In Interface Builder, start by dragging out a vertical stack view, and add the flowers label, image view, and edit button. Then set up the constraints as shown.

enter image description here

Upvotes: -2

Martin Muldoon
Martin Muldoon

Reputation: 3436

You need to add constraints to set the the placement of the StackView. To set the distance between the two controls, simply set the spacing as I've done in the image below (Spacing = 50):

enter image description here

Upvotes: 11

Abhishek Jain
Abhishek Jain

Reputation: 4737

You can add the width constraint to change the width.

Upvotes: 3

Related Questions