4

I'm trying to figure out how to limit a UICollectionView to display a horizontal scrollable list in a single row.

Any Ideas?

Johan Öhberg
  • 51
  • 1
  • 2

1 Answers1

1

I just used something that is working for me:

  1. Set the Scroll direction to Horizontal.
  2. Set the size of your Cells using sizeForItemAt indexPath method.
  3. Set a constraint to your CollectionView making its height equal to (or a bit greater than) the Cell's height which you specified above.

The logic behind it:

When the height of CollectionView is equal to the height of it's items and it is set to horizontal scroll, then it can only show them in one row. I said "or a bit greater than cell's height" because if you set the height of your CollectionView twice bigger than cell's height then it can fit 2 rows of cells and it will show them in 2 rows instead of one.

Nathan Tuggy
  • 2,239
  • 27
  • 28
  • 36
Abed Naseri
  • 502
  • 1
  • 8
  • 17