I want to use UICollectionView
to display a horizontal scrollable list of thumbnails, however, I want this to be a single row. On another view, I'm displaying the thumbnails in a UICollectionView
but this one scrolls vertically and it's in a single column.
Currently, the way I'm doing this is by changing the size of the collection view to only be big enough for one item so it autowraps and works, but now I'm dealing with variable sized items so it doesn't work anymore.
How do you make a UICollectionView
display one row or column?
I found that setting the
minimumLineSpacing
just made my scroll area really big and that setting theminimumInteritemSpacing=big
accomplished keeping the items in one scrolling row or column, centered in the middle of thecollectionview
.I wanted one column, left aligned and the other answers didn't help me.
So here is my very simple solution for one column, left aligned:
you also should set something like
Don't forget to remove the line
From the other solutions.
Hope this is helpful because it's a completely different approach compared to the other answers.
For Swift 3
There isn't a real reason to subclass if you can trust the type cast.
If you have your collectionView loaded from a nib you could also play around with the parameters in the Attributes and Size Inspectors.
Same goes for scroll direction.
I am guessing you are using the built in
Flow Layout
. However, for your case, you should make a customUICollectionView Layout
. Make it subclass ofUICollectionViewFlowLayout
and add this code in theinit
method:The
minimumLineSpacing
is the key to making it have one line here.I hope this helps!