Swift: UICollectionViewCell didSelectItemAtIndexPath Change backgroundColor

前端 未结 4 1042
傲寒
傲寒 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:12

    You can override UICollectionViewCell isSelected . It will apply changes in selected method.

    class ButtonCollectionCell: UICollectionViewCell {
    
                override var isSelected: Bool{
                    didSet{
                        if self.isSelected
                        {
                           self.layer.backgroundColor =  colorLiteral(red: 0.8058760762, green: 0.2736578584, blue: 0.1300437152, alpha: 1)
    
                        }  else
                        {
                           self.layer.backgroundColor =  colorLiteral(red: 0, green: 0, blue: 0, alpha: 0)
    
                        }
                    }
                }
    
        }
    

提交回复
热议问题