How change the Selection Color in Compositional Layouts in CollectionView

I've recently worked with Compositional Layouts with Diffable DataSource. I've implemented side bar using UICollectionLayoutListConfiguration(appearance: .sidebar). I want to change the collection cell selection color to a custom color. I've used following code.


let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, MenuData> { (cell, indexPath, item) in

let red = UIView()
red.backgroundColor = UIColor.red
cell.selectedBackgroundView = red

var content = cell.defaultContentConfiguration()
content.text = item.menuTitle
content.image = item.image
cell.contentConfiguration = content

}

though it applys the selection color, default cell configuration got override. is there any other approach to change the selection color


Xcode 12.2 beta allows you to use tintColor to specify a different color for the standard cell.defaultContentConfiguration():

cell.tintColor = .red
How change the Selection Color in Compositional Layouts in CollectionView
 
 
Q