'UICollectionView footer inset cannot set to zero
I'm trying to create a collectionview where the header and footer should have zero space to the cells
For some reason the footer insists on having 8 points spacing, any ideas are welcome.
self.setsCollectionView.contentInset = UIEdgeInsets(top: 10, left: 10, bottom: 0, right: 10)
self.setsCollectionView.register(supplementaryNib: SingleSetCollectionHeaderReusableView.self, type: .header)
self.setsCollectionView.register(nib: SingleSetRepetitionCollectionViewCell.self)
self.setsCollectionView.register(supplementaryNib: SingleSetCollectionFooterReusableView.self, type: .footer)
self.setsCollectionView.refreshControl = UIRefreshControl()
self.setsCollectionView.refreshControl?.addTarget(self, action: #selector(TrainingDashBoardViewController.refresh), for: .valueChanged)
self.setCollectionViewLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
self.setCollectionViewLayout.scrollDirection = .vertical
self.setCollectionViewLayout.sectionInset = .zero
self.setCollectionViewLayout.minimumInteritemSpacing = 0
self.setCollectionViewLayout.minimumLineSpacing = 0
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return .zero
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
let width = collectionView.frame.width - (collectionView.contentInset.left + collectionView.contentInset.right)
return CGSize(width: width, height: 44)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
let width = collectionView.frame.width - (collectionView.contentInset.left + collectionView.contentInset.right)
if #available(iOS 15.0, *) {
guard let set = self.dataSource.sectionIdentifier(for: section) else { return .zero }
return CGSize(width: width, height: set.repetitions.isEmpty ? 56 : 44 )
} else {
return CGSize(width: width, height: 44)
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

