Playing with Collection Views is so much fun and challenging. One of the things I came across is using gradients with collection views.
Adding gradient to a UICollectionView or UICollectionViewCell is as simple as adding it to any other view. We had a detailed discussion over it in the previous article.
Another challenge is, what if we need to add gradient to a UICollectionViewCell on selection and remove it when the UICollectionViewCell is de-selected.
Before we start coding, let’s see what we already have 🧐 and how can we use that to solve our problem statement.
Adding gradient to a view — In this article we had a detailed discussion on how to get that working.
Changing the UICollectionViewCell’s properties based on its selection state — Here we have already discussed how isSelected handles that.
Combining the above 2, now we’re left with “adding the gradient to cell when it is selected and removing it when it is de-selected”. We’re already halfway there, just need to put our knowledge in the right place. 🎯
The project includes all the implementation details of how you can handle UICollectionViewCell selection with gradient.
For more iOS related stuff, you can follow me here.
