Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView - Horizontal scroll, horizontal layout?

I have a UIScrollView that lays out a grid of icons. If you were to imagine the layout for the iOS Springboard, you'd be pretty close to correct. It has a horizontal, paged scroll (just like Springboard). However, it appears that the layout is not quite right. It appears as though it is laying out the items from top to bottom. As a result, my last column only has 2 rows in it, due to the number of items to be displayed. I'd rather have my last row on the last page have 2 items, like you would see in the Springboard.

How can this be accomplished with UICollectionView and its related classes? Do I have to write a custom UICollectionViewFlowLayout?

like image 680
Shadowman Avatar asked Oct 10 '13 16:10

Shadowman


People also ask

What is Uicollectionviewflowlayout?

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

What is compositional layout?

A compositional layout is composed of one or more sections that break up the layout into distinct visual groupings. Each section is composed of groups of individual items, the smallest unit of data you want to present. A group might lay out its items in a horizontal row, a vertical column, or a custom arrangement.


1 Answers

Have you tried setting the scroll direction of your UICollectionViewFlowLayout to horizontal?

[yourFlowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; 

And if you want it to page like springboard does, you'll need to enable paging on your collection view like so:

[yourCollectionView setPagingEnabled:YES]; 
like image 50
Erik Hunter Avatar answered Oct 05 '22 07:10

Erik Hunter