iosuicollectionviewuicollectionviewlayout

Can a UICollectionView scroll vertically with a columnar layout?


I am building UICollectionView that needs to scroll vertically, but lay out its items in a columnar format in order to handle varying item heights, like this:

enter image description here

A column-by-column layout is the default for a horizontally-scrolling collection view, but mine needs to scroll vertically. What's the easiest way to accomplish this? Do I need to subclass UICollectionViewLayout, or can UICollectionViewFlowLayout do it? Or...?


Solution

  • It turns out there is a subclass of UICollectionViewLayout called SelfSizingWaterfallCollectionViewLayout on GitHub that does exactly what I needed.