Maybe we’re spoilt by UITableView or maybe we’re graced with it, either way UICollectionViews are not as well rounded.
I needed to make the supplementary views in my UICollectionView behave like UITableViewCells do when you touch down on them, i.e. support a background colour and a method call when it happens.
UICollectionViews don’t really support this behaviour at all, I had previously added a single UIGestureRecognizer to each supplementary view so I knew when they were tapped but it didn’t allow me to do the correct highlighting behaviour.
Here’s what I did:
1. Subclass UICollectionView
Given that there’s no more convenient way to do it we’ll need to override UIResponder’s touchesBegan, touchesEnded and touchesCancelled within our UICollectionView subclass:
2. Create a setHighlighted method in your supplementary view
This is what the touches methods are calling to notify your supplementary view it’s being touched.
3. Fix any existing CollectionView wide gestures
I had a long press gesture on the whole UICollectionView that I was using for some cell behaviour, I needed to set;
longPressGesture.delaysTouchesBegan = NO;