I'm trying to build a list similiar to WhatsNewKit(WhatsNewKit) using the new CollectionView API.
My problem is that I can't seem to remove the cell separators.
I am using as a cell the UICollectionViewListCell and so far I tried to change the cell separatorLayoutGuide like this cell.separatorLayoutGuide.heightAnchor.constraint(equalToConstant: 0).isActive = true
but it just tells me that it breaks the CollectionView constraints.
( "<NSLayoutConstraint:0x600002364b90 UILayoutGuide:0x60000390a060'UICollectionViewListCellSeparatorLayoutGuide'.height == 0 (active)>", "<NSLayoutConstraint:0x600002364730 'UICollectionViewListCell-height-separatorLayoutGuide-constraint' UILayoutGuide:0x60000390a060'UICollectionViewListCellSeparatorLayoutGuide'.height == 0.333333 (active)>" )
Will attempt to recover by breaking constraint <NSLayoutConstraint:0x600002364730 'UICollectionViewListCell-height-separatorLayoutGuide-constraint' UILayoutGuide:0x60000390a060'UICollectionViewListCellSeparatorLayoutGuide'.height == 0.333333 (active)>)
So is there a way to remove those separators?

You can hide the separator by changing property showsSeparators of UICollectionLayoutListConfiguration (you probably pass UICollectionLayoutListConfiguration to your collectionView.collectionViewLayout when configuring your collection view layout).
Example usage:
let provider = {(_: Int, layoutEnv: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in
var configuration = UICollectionLayoutListConfiguration(appearance: .grouped)
configuration.showsSeparators = false // <----- hide separators
return .list(using: configuration, layoutEnvironment: layoutEnv)
}
collectionView.collectionViewLayout = UICollectionViewCompositionalLayout(sectionProvider: provider)
Same as accepted answer, just with plain layout:
var config = UICollectionLayoutListConfiguration(appearance: .plain)
config.showsSeparators = false
let layout = UICollectionViewCompositionalLayout.list(using: config)
collectionView.collectionViewLayout = layout
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With