Here is my code currently. The problem is that the beige background color is there even when I select the cell. I know I should set a different background configuration for every state that I need to, but I don't know how for this default cell. I have created custom UICollectionViewListCells and set a different background on those depending on state. But can't figure out how to do that with the default cells.
Code Block let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, CellItem> { (cell, indexPath, cellItem) in var content = cell.defaultContentConfiguration() content.text = cellItem.title content.secondaryText = cellItem.subText if let imageName = cellItem.imageName { content.image = UIImage(named: imageName) } cell.contentConfiguration = content cell.accessories = [.disclosureIndicator()] var backgroundConfig = UIBackgroundConfiguration.listGroupedCell() /* Set a beige background color to use the cell's tint color. */ backgroundConfig.backgroundColor = UIColor(named: "CellColor") backgroundConfig.strokeColor = .green cell.backgroundConfiguration = backgroundConfig }
If you want to customize the background configuration for specific states, you need to override updateConfiguration(using state:) in a cell subclass, which is called anytime the state changes so you'll be able to update the configuration as desired for the new state.
Setting a background configuration on the cell with customized properties won't allow the appearance to change for different states; only non-customized properties are automatically updated based on the default values for the configuration in the new state.
Setting a background configuration on the cell with customized properties won't allow the appearance to change for different states; only non-customized properties are automatically updated based on the default values for the configuration in the new state.