I have been working with UICollectionView and UICollectionViewCell for quiet a long time now.
Showing selection of a particular collection view cell is a very frequent issue faced by those working with collection views. I am refering to something like this,
In your custom UICollectionViewCell subclass, just override isSelected property, i.e.
isSelected is a UICollectionViewCell’s stored property that represents the cell selection state. The selected state is toggled when the user lifts up from a highlighted cell.
In your UICollectionViewCell subclass, you just need to override this property and provide your custom implementation. Example: You can set property observers on it so that you are notified of any changes made in the property for a particular cell, i.e.
Whenever a particular UICollectionViewCell is selected by the user:
So, as a result, the isSelected will be set either true/false for all the cells , every time a cell is selected by the user.
To achieve the desired result:
Now, to show when a cell selected/de-selected, you just need to change some of the properties of the cell according to you requirements.
I have used cell’s transform, backgroundColor and a custom imageView isHidden state properties to highlight the cell’s selection state. You can use others as well according to your requirement.
Don’t forget to read my other articles:
Watch this space for more on UICollectionView and UICollectionViewCell. Feel free to drop your queries if you have any.