SWIFT: How to make UICollectionView items fill row before returning to line

275 views Asked by At

This is what I have implemented: enter image description here

See the black space on the right, it could still hold two extra items. But for some reason, starting from the 7th item, the rendering starts at the next line.
My layout configuration only changes two parameters:

class CarouselFlowLayout: UICollectionViewFlowLayout {
    override init() {
        super.init()
        minimumLineSpacing = 40
        minimumInteritemSpacing = 20
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func prepare() {
        super.prepare()
    }
}

Any idea, which parameters should I configure in order to force the collectionView to fill each "row" before returning to the next line?

1

There are 1 answers

0
AG_HIHI On

All I needed to do is set scrollDirection to horizontal:

  override init() {
        super.init()
        // This needs to be vertical in order for the collectionView to fill rows before columns in the case of displaying the whole collection view as a grid like in VoirTout page
        scrollDirection = .vertical
        minimumLineSpacing = 40
        minimumInteritemSpacing = 20
    }