In case anyone is looking for a solution without code, I created an example to do this completely in the storyboard, using Auto Layout.
You can get it from github.
Basically, to recreate the example (for vertical scrolling):
- Create a
UIScrollView, and set its constraints. - Add a
UIStackViewto theUIScrollView - Set the constraints:
Leading,Trailing,Top&Bottomshould be equal to the ones fromUIScrollView - Set up an equal
Widthconstraint between theUIStackViewandUIScrollView. - Set Axis = Vertical, Alignment = Fill, Distribution = Equal Spacing, and Spacing = 0 on the
UIStackView - Add a number of
UIViewsto theUIStackView - Run
Exchange Width for Height in step 4, and set Axis = Horizontal in step 5, to get a horizontal UIStackView.