10

I would like to have a paged UICollectionView, with each page displaying cells from left to right. What I can achieve now with classic UICollectionViewFlowLayout and

layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

The result is the following :

      page 1             page 2
 cell 1 | cell 3 || cell 5 | cell 7
 cell 2 | cell 4 || cell 6 | cell 8

What I would like to achieve now is:

      page 1             page 2
 cell 1 | cell 2 || cell 5 | cell 6
 cell 3 | cell 4 || cell 7 | cell 8

I would like to know if there is simpler solution than creating my own flow controller ? Or if not, is there some place where I can see the source code for UICollectionViewFlowLayout which is not so different of what I want ?

Peter Pei Guo
  • 7,770
  • 18
  • 35
  • 54
PhilippeAuriach
  • 2,418
  • 2
  • 22
  • 41
  • 1
    Although the method in [this answer](https://stackoverflow.com/a/26495922/1671176) is correct but the suggested sample code does not work. Below is the sample code I developed that works fine. https://github.com/siddharth-paneri/HoizontalCollectionViewLayout – Siddharth Paneri Apr 24 '18 at 11:03

1 Answers1

12

I finally made my own layout subclassing UICollectionViewFlowLayout : I replace each cell's collectionViewAttributes with the corresponding one if it was a classic collectionViewFlowLayout, using a little bit of maths.

It now fits my needs, and could be useful for someone else, so here is my code: https://github.com/philippeauriach/fullyhorizontalcollectionview

PhilippeAuriach
  • 2,418
  • 2
  • 22
  • 41
  • It does not work. It is random order of numbers. Only first cell in each row is right, e.g Row#1 0 | 28 | 22 | 16 | 10 | 4 | 32 Row#2 7 | 1 | 29 | .. . . . . . . – W.S Sep 01 '16 at 03:12