修改当前可见单元格的内容-UICollectionViewCell

时间:2019-09-26 23:45:57

标签: swift xcode uicollectionview uicollectionviewcell

我有一个UICollectionViewCell。我有isPagingEnabled。我想在单元格可见时添加边框颜色和阴影。我已经添加了此代码,它无法正常工作。

extension CarouselTVC : UICollectionViewDelegate {

    func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "carouselCVC", for: indexPath) as! CarouselCVC
        cell.elevate(elevation: 8.0, color: .red, opacity: 0.16)
        cell.layer.borderWidth = 1.0
        cell.layer.borderColor = UIColor.red.cgColor

        print("Will Display")
    }

    func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "carouselCVC", for: indexPath) as! CarouselCVC

        cell.layer.borderWidth = 0.0
        cell.layer.borderColor = UIColor.clear.cgColor
        cell.layer.shadowOpacity = 0.0

        print("Did End Display")

    }
}

0 个答案:

没有答案
相关问题