UICollectionViewCell 中的元素没有得到 highlighted/selected
elements inside the UICollectionViewCell are not getting highlighted/selected
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 是 highlighted/selected 和 UILabel
但 shadowView(UIView)
没有 highlighted/selected
你检查过那些元素的背景了吗?如果它们是白色的,它们将在内容视图改变颜色时保持白色。您需要确保它们是清晰的背景,以便您可以通过它们自己的背景看到内容视图的颜色。
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 是 highlighted/selected 和 UILabel
但 shadowView(UIView)
没有 highlighted/selected
你检查过那些元素的背景了吗?如果它们是白色的,它们将在内容视图改变颜色时保持白色。您需要确保它们是清晰的背景,以便您可以通过它们自己的背景看到内容视图的颜色。