Fitting all items into one collection view row

Is there a way to make all items in a collection view fit in one row and scroll horizontally? I want to automatically place items in an another row. Instead, my collection view items (which are returning from a server) are going on separate rows. I'm trying to copy something like Instagram's story display. (I would post a like but it has to get approved and this is pretty urgent). Thanks for any help/advice in advance.



    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return pictures.count
    }

It depends a bit on exactly what you have in mind. If your layout has only a single section, then I think you can set the collection view's flow layout's "scrollDirection" property to "horizontal". In addition, you would have to ensure that the height of the collection view was fixed, the width was unlimited, and that the individual views were sized so that only one view fits in the height.


If you have multiple sections, and you want each section to be a single row, but with multiple sections stacked vertically, you may not be able to configure the standard flow layout to get the desired results. You might in that case have to provide your own UICollectionViewLayout subclass.


I would suggest you go back through the last few years of WWDC session videos, and watch the ones about UICollectionView. The early ones, especially, might have examples of configuring collection views for different geometries.


BTW, this is not a Swift question. It really ought to be in the Cocoa Touch forum.

Fitting all items into one collection view row
 
 
Q