UICollectionViewCell内的元素未突出显示/已选中

时间:2018-05-04 04:03:22

标签: swift uicollectionviewcell

enter image description here

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)未突出显示/已选中

1 个答案:

答案 0 :(得分:0)

你检查过这些元素的背景吗?如果它们是白色,则在内容视图改变颜色时它们将保持白色。您需要确保它们是清晰的背景,以便您可以通过自己的背景查看内容视图颜色。