'iOS - Change UICollectionView layout to fill rows instead of columns
Solution 1:[1]
I had the exact same issue as you. Collectin view is horizontal & none-scrollable, but it was filling columns first. Weirdly though, changing the direction to "Vertical" fixed the issue though!
Solution 2:[2]
This takes me long hours of tries and finally what solved it was to change the scroll direction to vertical
layout.scrollDirection = .vertical //in case of horizontal collection
layout.scrollDirection = .horizontal //in case of vertical collection
Solution 3:[3]
Yes it is possible.
- Make sure the the collection view's width is equal to the screen
- To have 3 cells on each row, you have to make sure the 3 cells will be able to fit the width of the screen.
- Example: get the width of the screen & divided it by 3. Then set that value to the width of each cell. Also, for these three cells to fit in one row, the spacing between cells has to be zero. By doing that you have 3 cells that will fit exactly on the width of the screen for each row. if you want to add space between each cell, just divide the width of the screen by less than 3.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Abdurrahman |
Solution 2 | A_Mo |
Solution 3 | Joshua Geronimo |