Swift: UICollectionViewCell didSelectItemAtIndexPath Change backgroundColor

前端 未结 4 1032
傲寒
傲寒 2021-02-09 15:39

I\'m easily able to change the background color of a cell in the CellForItemAtIndexPath method

func collectionView(collectionView: UICollectionView,         


        
4条回答
  •  失恋的感觉
    2021-02-09 16:16

    You can use this method for that:

        func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){
    
        var cell : UICollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath)!
        cell.backgroundColor = UIColor.magentaColor()
    }
    

提交回复
热议问题