override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let cell = collectionView.cellForItem(at: indexPath) {
cell.contentView.backgroundColor = Colors.lightGrayDivider
}
}
override func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
if let cell = collectionView.cellForItem(at: indexPath) {
cell.contentView.backgroundColor = .white
}
}
override func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath) {
if let cell = collectionView.cellForItem(at: indexPath) {
cell.contentView.backgroundColor = Colors.lightGrayDivider
}
}
override func collectionView(_ collectionView: UICollectionView, didUnhighlightItemAt indexPath: IndexPath) {
if let cell = collectionView.cellForItem(at: indexPath) {
cell.contentView.backgroundColor = .white
}
}
问题:UICollectionView
的contentView与UILabel
一起突出显示/选中,但shadowView(UIView)
未突出显示/已选中
答案 0 :(得分:0)
你检查过这些元素的背景吗?如果它们是白色,则在内容视图改变颜色时它们将保持白色。您需要确保它们是清晰的背景,以便您可以通过自己的背景查看内容视图颜色。