title: highlighting uicollectionview cell on tap
body: <p>I have a slide-out menu that I have implemented as a UICollectionViewController. I have created custom cells for the collection view as well. The navigation and everything works as expected. What I am having trouble with is changing the cells appearance when I click on an actual cell. </p>
  
  <p>I've tried several approaches based on solutions(<a href="https://stackoverflow.com/questions/23392485/change-background-of-uicollectionview-cell-on-tap">1</a>)(<a href="https://stackoverflow.com/questions/14637031/why-uicollectionviews-uicollectionviewcell-is-not-highlighting-on-user-touch">2</a>) I've seen here on stack but nothing to my satisfaction. </p>
  
  <p><strong>Solution 1</strong>: implement the UICollectionViewController delegate methods:</p>
  
  <pre><code>class SlideOutMenuViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout{
     //Setup code and other delegate methods….
  
      override func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath) {
          let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! SlideOutMenuCells
  
          cell.backgroundColor = .white
      }
  
      override func collectionView(_ collectionView: UICollectionView, didUnhighlightItemAt indexPath: IndexPath) {
          let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! SlideOutMenuCells
  
          cell.backgroundColor = UIColor.mainGreen()
      }
  }
  </code></pre>
  
  <p>When I tried this solution, nothing happens. The cells background color doesn't change colors. </p>
  
  <p><strong>Solution 2</strong>: This solution results in better results except the cell on changes colors when I hold the cell. I'd like the cells background color to flash or highlight quickly on a <strong><em>tap</em></strong> and not really just if the user holds the cell down. </p>
  
  <pre><code>class SlideOutMenuCells: UICollectionViewCell {
  
      //Setup code...
  
      override var isHighlighted: Bool {
          didSet {
              if self.isHighlighted {
                  backgroundColor = UIColor.darkGreen()
              } else {
                  backgroundColor = UIColor.mainGreen()
              }
          }
      }
  }
  </code></pre>
  
  <p>Neither solution really works as intended. I've seen several posts here that try addressing this but haven't found one with a solution that works really. I would like the cell to flash highlight with a tap, and not just when a user clicks and holds on a cell...</p>