How to create a collection view of strings that scrolls horizontally but is fixed vertically?

I am trying to make a UICollectionView, which is 1 x N, that scrolls horizontally but is locked vertically, so it doesn't move vertically at all.

Any ideas or pointers on how to achieve this?

+6
source share
4 answers

Use the flow layout and set the scroll direction property to horizontal.

The documentation is here .

+18
source

Use the flow layout and set the scroll direction to β€œHorizontal” to fix the problem.

let flowLayout = UICollectionViewFlowLayout() flowLayout.itemSize = CGSizeMake(UIScreen.mainScreen().bounds.width/2 - 10, 190) flowLayout.sectionInset = UIEdgeInsetsMake(0, 5, 0, 5) flowLayout.scrollDirection = UICollectionViewScrollDirection.Horizontal flowLayout.minimumInteritemSpacing = 0.0 mainHomeCollectionView.collectionViewLayout = flowLayout 
+3
source

I just did a similar thing and posted the code on github.

I wrote a small algorithm that tracks selectedIndexPath as well as the previous cell position.

https://github.com/texas16/HorizontalCollectionView

enter image description here

+2
source

SWIFT 3

  let flowLayout = UICollectionViewFlowLayout() flowLayout.itemSize = CGSize(width: UIScreen.main.bounds.width/2-10, height: 190) flowLayout.sectionInset = UIEdgeInsetsMake(0, 5, 0, 5) flowLayout.scrollDirection = UICollectionViewScrollDirection.horizontal flowLayout.minimumInteritemSpacing = 0.0 mainCollectionView.collectionViewLayout = flowLayout 
0
source

All Articles