1

UICollectionViewFlowLayout goes left-to-right in a row, then wraps to the next row. I want a layout that goes top-to-bottom, then wraps back up to the next column. Think of it as a UITableView that wraps into multiple columns, which scrolls horizontally.

UICollectionViewFlowLayout is close to what I want – can I subclass it or must I subclass UICollectionViewLayout and start from scratch? (This answer leads me to believe I can't use flow layout.)

    Visible Screen
    [ 1   6   11 ] 16
    [ 2   7   12 ] 17
    [ 3   8   13 ] 18
    [ 4   9   14 ]
    [ 5   10  15 ]
Community
  • 1
  • 1
zekel
  • 9,227
  • 10
  • 65
  • 96
  • possible duplicate of [UICollectionView horizontal paging - can I use Flow Layout?](http://stackoverflow.com/questions/16678474/uicollectionview-horizontal-paging-can-i-use-flow-layout) – BB9z Dec 31 '14 at 09:37

2 Answers2

2

You can achieve it using UICollectionViewFlowLayout - just set the property 'scrollDirection' to 'UICollectionViewScrollDirectionHorizontal' and you get what you want.

About UICollectionViewLayout:

UICollectionViewLayout is meant to be subclassing. You need to override some methods over there in order to get a specific layout. Take a look at the documentation, or WWDC 2012 video tutorial.

Avi Tsadok
  • 1,843
  • 13
  • 19
  • I think the `scrollDirection` property only controls where the left-to-right rows wrap, it won't make them layout as top-to-bottom columns. – zekel Jun 25 '13 at 13:32
  • Just tested it - it works! Just set scrollDirection to 'UICollectionViewScrollDirectionHorizontal' and it does what he needs... (i'm editing my answer) – Avi Tsadok Jun 25 '13 at 13:51
  • Geez, you're absolutely right. That's what I get for posting early in the morning. Thanks very much. – zekel Jun 25 '13 at 13:57
2

This might point you in the right direction: https://github.com/chiahsien/UICollectionViewWaterfallLayout

You might want to create your own layout subclass, which is not as hard as it might sound. See this tutorial: http://skeuo.com/uicollectionview-custom-layout-tutorial

Johannes Fahrenkrug
  • 42,912
  • 19
  • 126
  • 165