For iOS 14, I think you have to subclass UICollectionViewListCell and override updateConfiguration(using state: UICellConfigurationState). It should work for iOS 15 also.
let cellConfiguration = UICollectionView.CellRegistration<MyCell, String>....
override func updateConfiguration(using state: UICellConfigurationState) {
super.updateConfiguration(using: state)
guard var cConfig = self.contentConfiguration?.updated(for: state) as? UIListContentConfiguration else { return }
cConfig.textProperties.colorTransformer = UIConfigurationColorTransformer { color in
state.isSelected || state.isHighlighted ? .white : .black
}
cConfig.secondaryTextProperties.colorTransformer = UIConfigurationColorTransformer { color in
state.isSelected || state.isHighlighted ? .white : .black
}
self.contentConfiguration = cConfig
guard var bConfig = self.backgroundConfiguration?.updated(for: state) else { return }
bConfig.backgroundColorTransformer = UIConfigurationColorTransformer { color in
state.isSelected || state.isHighlighted ? .systemPink : .systemGray5
}
self.backgroundConfiguration = bConfig
}
}
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: