Small gaps appearing in UICollectionView section

To add on to the answer of @Magoo:

A CGSize structure is sometimes used to represent a distance vector, rather than a physical size. As a vector, its values can be negative. To normalize a CGRect structure so that its size is represented by positive values, call the standardized function.

In Swift 2.x you will need to use:

return CGSizeMake(width:collectionView.bounds.size.width,height:ceil(calculatedHeight)

As of Swift 3 you can no longer use CGSizeMake:

return CGSize(width:collectionView.bounds.size.width,height:ceil(calculatedHeight)
  • The ceil function rounds a number UP to the nearest integer, if necessary.
  • For rounding down you have floor.

I've only gone and solved it... hours after putting a 300 bounty on it..

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

 // calculated CGSize...

  return CGSize(width:collectionView.bounds.size.width,height:ceil(calculatedHeight) 

}

remember @2x @3x always ceil your calculated cells... UICollectionViews can't hack 0.5 points