Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a single row collection view that scrolls horizontally but is fixed vertically?

Tags:

ios

Im trying to make a UICollectionView that is 1 x N that scrolls horizontally but is locked vertically so it does not move vertically at all.

Any ideas or pointers on how to achieve this?

like image 924
Nirma Avatar asked Mar 01 '13 20:03

Nirma


People also ask

How do I make my collection scroll horizontally?

You need to reduce the height of UICollectionView to its cell / item height and select " Horizontal " from the " Scroll Direction " as seen in the screenshot below. Then it will scroll horizontally depending on the numberOfItems you have returned in its datasource implementation.

What is Uicollectionviewflowlayout?

A layout object that organizes items into a grid with optional header and footer views for each section.

What is collection view layout?

A layout object determines the placement of cells, supplementary views, and decoration views inside the collection view's bounds and reports that information to the collection view. The collection view then applies the provided layout information to the corresponding views so that they can be presented onscreen.


2 Answers

Use flow layout and set scroll direction to horizontal to fix your problem.

let flowLayout = UICollectionViewFlowLayout()
flowLayout.itemSize = CGSize(width: UIScreen.main.bounds.width/2 - 10, height: 190)
flowLayout.sectionInset = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
flowLayout.scrollDirection = .horizontal
flowLayout.minimumInteritemSpacing = 0.0
mainHomeCollectionView.collectionViewLayout = flowLayout
like image 129
Himanshu Avatar answered Oct 03 '22 02:10

Himanshu


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

Documentation here.

like image 20
jrturton Avatar answered Oct 03 '22 03:10

jrturton