How can I achieve this layout:

The content flows like the UICollectionViewFlowLayout with UICollectionViewScrollDirectionHorizontal, but there can be more than one section depending on collection view size. Also, the sections don't occupy full height