我需要显示UICollectionView
中每个单元格的分隔符,除了一个部分的每个第一个单元格。我使用列表布局。到目前为止,我只能使用configuration.showsSeparators = false
删除所有分隔符。
我的UICollectionView
配置:
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)
}()
小区注册:
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)
}
1条答案
按热度按时间0g0grzrc1#
一个可能的解决方案是通过设置configuration.showsSeparators = false来删除默认分隔符,然后在单元格UI的底部添加一个行视图来创建分隔符的假象。