Small gaps appearing in UICollectionView section

Viewed 634

Very strange issue on UICollectionView...

I have a UIImageView below a UICollectionView and I noticed there are multiple hairline / 1px clear lines appearing at certain points in the collectionView... one appearing below a description cell...

first

Assuming it was a problem with the cell, I've investigated every way I could think with no joy. I've doubled up this cell to illustrate the issue happens in between IndexPath section 1 and item 6 and 7

Even when this cell is doubled up... the divider line cell below is part of the same section so it's definitely not a footer or a header???

second

My flowLayout is

flowLayout.scrollDirection = .vertical
flowLayout.minimumInteritemSpacing = 0.0
flowLayout.minimumLineSpacing = 0.0
flowLayout.sectionInset = UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0)
flowLayout.headerReferenceSize = .zero
flowLayout.footerReferenceSize = .zero

I made the background of the collectionView red to highlight the issue... I don't have a clue what the issue is.

View Hierarchy

view

Update

changing flowLayout.minimumLineSpacing = 0.0 to -1.0 'fixes' the issue in some places... why wouldn't this value remain accurate along all cells? and remain at 0.0??

flowLayout.scrollDirection = .vertical
flowLayout.minimumInteritemSpacing = 0.0
flowLayout.minimumLineSpacing = -1.0
flowLayout.sectionInset = .zero
3 Answers

I tried all the answers and nothing was working for me. Finally, I ended up adjusting my collectionView width so that the number of cells evenly divided into it.

Which solved the problem for me.

// Adjust the width of the collectionView, so that our cells divide evenly into it
CGFloat widthModulus = fmod(collectionViewWidth, numberOfCells);
CGFloat newCollectionViewWidth = collectionViewWidth - widthModulus;
Related