I need to show separators for every cell in UICollectionView except every first cell of a section. I'm using list layout.
So far I have only been able to remove all separators using configuration.showsSeparators = false.
My UICollectionView configuration:
let collectionView: UICollectionView = {
let provider = { (_: Int, layoutEnv: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in
var configuration = UICollectionLayoutListConfiguration(appearance: .grouped)
configuration.showsSeparators = true // <----- shows separators for every cell
configuration.footerMode = .supplementary
return .list(using: configuration, layoutEnvironment: layoutEnv)
}
let listLayout = UICollectionViewCompositionalLayout(sectionProvider: provider)
return UICollectionView(frame: .zero, collectionViewLayout: listLayout)
}()
Cell registartion:
let cellRegistration = UICollectionView.CellRegistration<MailboxCell, MailAccount> {
(cell, indexPath, listItem) in
// some setup code
}
dataSource = UICollectionViewDiffableDataSource<Account, ListItem>(collectionView: collectionView) {
(collectionView, indexPath, listItem) -> UICollectionViewCell? in
// some setup
return collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: listItem)
}