8

Every time I try to add something to a UIStackView in iOS it autosizes my subviews into something that is too small, so the text is being cut off.

How exactly is this StackView supposed to be used? All the guides said it was easy, just drag your subviews inside it, but I must be doing something wrong..

Before adding to StackView:

Before adding to StackView

After Adding to StackView:

After Adding to StackView

Jim Moody
  • 758
  • 2
  • 6
  • 18

1 Answers1

3

This is because stackview itself needs constraints. Add constraints to your stackview and then the stackview will take care of subviews.

enter image description here

In this case stackview is positioned horizontally and vertically center in container.

Let me know if there is still any issue.

Irfan
  • 5,070
  • 1
  • 28
  • 32
  • 4
    Did not work for me. Nothing but frustration, as usual with autolayout. – user3259235 May 01 '16 at 11:54
  • @user3259235 Are you using stackview? What's your problem and what have you tried? – Irfan May 02 '16 at 05:46
  • I've figured out that stack view has two options, equal sizing and proportionate based on intrinsic size, based on the subviews content. I'd like an option to set the proportion based on my own settings and let the content update without moving around in the stack view, which is what I was trying to do. That's not there, so I've moved on. – user3259235 May 07 '16 at 10:41
  • Your instructions just place the stack view in the middle of the superview. What does it have to do with resizing inner labels? UPD The problem of OP is solved by changing the horizontal width of the stack view. – rommex Sep 13 '17 at 10:43
  • @rommex, This is just an example. You can move this stackview to any other place by giving leading and top constraint. If you fixed the width and height and text increases than the subview won't resize. – Irfan Sep 13 '17 at 11:50
  • Thank you @Irfan, this fixed my problem! – JIANG Nov 02 '17 at 15:28