How to make 2 rows in horizontal collection view without using sections

4.4k Views Asked by At

The horizontal scrolling in UICollectionView only returns one row and I need to make a horizontal scrolling collection view with 2 rows just like the image below

[1]: https://i.stack.imgur.com/Vs1kt.png :[1]

1

There are 1 best solutions below

4
On BEST ANSWER

You need to set fix height of the CollectionView and then use sizeForItemAt() under UICollectionViewDelegateFlowLayout which returns CGSize. You have to manage the cell height something like this.

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

            return CGSize(width: 50.0, height: collectionViewHeight / 2) //<-- Manage height and width accordingly.
        }