3

Using Stack View, I want to get 3 items next to each other, which I achieved:

However, what I am looking to do is if the screen is too small to fit everything nicely in, then to move the block to the next line such as: enter image description here

Should I not be using Stack View for this?

Github version of sample project: https://github.com/jzhang172/StackTest

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Snorlax
  • 4,425
  • 8
  • 37
  • 68

1 Answers1

0

UIStackViews cannot do that kind of automatic layout where it sends overflow to a new row AFAIK. For what you are trying to do there are several other options depending on your purpose.

  1. Embed several stackviews in a large UIScrollView and size it to only show your first row. Later could "grow" that scrollview to expose additional stackviews as needed.

  2. You could dynamically create additional UIStackViews located in the lower position and fill them as needed.

  3. You could consider a UICollectionView instead.

BTW: There is a github project for OS X embedding stack views in a scrollview dynamically. It might help you out: StackViewTest

caxix
  • 1,085
  • 1
  • 13
  • 25