Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change UICollectionView Scroll Direction?

I have successfully implemented a UICollectionView. Is it possible to change the scrollDirection?

Can you please show how to implement it programmatically?

like image 285
Entitize Avatar asked Aug 30 '15 01:08

Entitize


People also ask

How do I make my UICollectionView scroll horizontal?

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.


1 Answers

This is how you create it in code with UICollectionViewFlowLayout

let layout = UICollectionViewFlowLayout() layout.scrollDirection = .vertical let collectionView = UICollectionView(frame: frame, collectionViewLayout: layout) 

or if you are working with an existent collection view

if let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {     layout.scrollDirection = .vertical } 
like image 148
Sash Zats Avatar answered Sep 21 '22 13:09

Sash Zats