Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal Stack View New Row - Swift

Stack Views's in iOS are a beautiful thing but I have realized there is no native way to create new rows in horizontal stack views. Let's say I dynamically added subviews in a horiztonal stack view and would want to create a new row once I reach an increment of 3 subviews respectively.

subview array stacked horizontally and vertically

Would I be required to create a vertical stack view then programmatically populate it with individual horizontal stack views at an interval of 3 increments?

If so, would swift support dynamic variable creation of horzStackView1, horzStackView2, ... ?

I'm starting to believe there is an easier way to implement this but I can't think of anything as I'm new to Swift 2.

like image 584
theflarenet Avatar asked Mar 25 '16 15:03

theflarenet


1 Answers

Yes, you would have to manually setup the the vertical and horizontal stack views yourself.

You may want to look into using UICollectionView it supports having cells automatically wrap onto the next row if there is not enough space.

like image 95
Craig Siemens Avatar answered Oct 19 '22 08:10

Craig Siemens