title: CollectionView cell does not change backgroundColor
body: <p>As the title says, I'm incurred in a little trouble using UltraVisualLayout class. When I change the background color to my cell (using UltraVisualLayout as custom layout in the collectionView) cells do not appear to have color, instead if I change to standard flow layout, the cells change their background colors.
  I use these lines to color the cells:</p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell
  {
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "squadraCell", for: indexPath)
  
      switch (indexPath.row % 5)
      {
          // ho provato anche con cell.contentView.backgroundColor ma non funziona nemmeno così
          case 0: cell.contentView.backgroundColor = UIColor.yellow()
          case 1: cell.contentView.backgroundColor = UIColor.orange()
          case 2: cell.contentView.backgroundColor = UIColor.red()
          case 3: cell.contentView.backgroundColor = UIColor.green()
          case 4: cell.contentView.backgroundColor = UIColor.blue()
          default: break
      }
  
      return cell
  }
  </code></pre>
  
  <p>Here my custom layout (<a href="https://www.raywenderlich.com/99087/swift-expanding-cells-ios-collection-views" rel="nofollow">https://www.raywenderlich.com/99087/swift-expanding-cells-ios-collection-views</a>)</p>
  
  <pre><code>//
  //  UltravisualLayout.swift
  //  RWDevCon
  //
  //  Created by Mic Pringle on 27/02/2015.
  //  Copyright (c) 2015 Ray Wenderlich. All rights reserved.
  //
  
  import UIKit
  
  /* The heights are declared as constants outside of the class so they can be easily referenced elsewhere */
  struct UltravisualLayoutConstants
  {
      struct Cell
      {
          /* The height of the non-featured cell */
          static let standardHeight: CGFloat = 100
          /* The height of the first visible cell */
          static let featuredHeight: CGFloat = 280
      }
  }
  
  class UltravisualLayout: UICollectionViewLayout
  {
  
      // MARK: Properties and Variables
  
      /* The amount the user needs to scroll before the featured cell changes */
      let dragOffset: CGFloat = 180.0
  
      var cache = [UICollectionViewLayoutAttributes]()
  
      /* Returns the item index of the currently featured cell */
      var featuredItemIndex: Int
      {
          get
          {
              /* Use max to make sure the featureItemIndex is never &lt; 0 */
              return max(0, Int(collectionView!.contentOffset.y / dragOffset))
          }
      }
  
      /* Returns a value between 0 and 1 that represents how close the next cell is to becoming the featured cell */
      var nextItemPercentageOffset: CGFloat
      {
          get
          {
              return (collectionView!.contentOffset.y / dragOffset) - CGFloat(featuredItemIndex)
          }
      }
  
      /* Returns the width of the collection view */
      var width: CGFloat
      {
          get
          {
              return collectionView!.bounds.width
          }
      }
  
      /* Returns the height of the collection view */
      var height: CGFloat
      {
          get
          {
              return collectionView!.bounds.height
          }
      }
  
      /* Returns the number of items in the collection view */
      var numberOfItems: Int
      {
          get
          {
              return collectionView!.numberOfItems(inSection: 0)
          }
      }
  
      // MARK: UICollectionViewLayout
  
      /* Return the size of all the content in the collection view */
      override func collectionViewContentSize() -&gt; CGSize
      {
          let contentHeight = (CGFloat(numberOfItems) * dragOffset) + (height - dragOffset)
  
          return CGSize(width: width, height: contentHeight)
      }
  
      override func prepare()
      {
          cache.removeAll(keepingCapacity: false)
  
          let standardHeight = UltravisualLayoutConstants.Cell.standardHeight
          let featuredHeight = UltravisualLayoutConstants.Cell.featuredHeight
  
          var frame = CGRect.zero
          var y: CGFloat = 0
  
          for item in 0..&lt;numberOfItems
          {
              let indexPath = NSIndexPath(item: item, section: 0)
              let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath as IndexPath)
              /* Important because each cell has to slide over the top of the previous one */
              attributes.zIndex = item
              /* Initially set the height of the cell to the standard height */
              var height = standardHeight
              if indexPath.item == featuredItemIndex {
                  /* The featured cell */
                  let yOffset = standardHeight * nextItemPercentageOffset
                  y = collectionView!.contentOffset.y - yOffset
                  height = featuredHeight
              } else if indexPath.item == (featuredItemIndex + 1) &amp;&amp; indexPath.item != numberOfItems
              {
                  /* The cell directly below the featured cell, which grows as the user scrolls */
                  let maxY = y + standardHeight
                  height = standardHeight + max((featuredHeight - standardHeight) * nextItemPercentageOffset, 0)
                  y = maxY - height
              }
              frame = CGRect(x: 0, y: y, width: width, height: height)
              attributes.frame = frame
              cache.append(attributes)
              y = frame.maxY
          }
      }
  
      /* Return all attributes in the cache whose frame intersects with the rect passed to the method */
      func layoutAttributesForElementsInRect(rect: CGRect) -&gt; [AnyObject]?
      {
          var layoutAttributes = [UICollectionViewLayoutAttributes]()
          for attributes in cache
          {
              if attributes.frame.intersects(rect)
              {
                  layoutAttributes.append(attributes)
              }
          }
  
          return layoutAttributes
      }
  
      /* Return the content offset of the nearest cell which achieves the nice snapping effect, similar to a paged UIScrollView */
      override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -&gt; CGPoint
      {
          let itemIndex = round(proposedContentOffset.y / dragOffset)
          let yOffset = itemIndex * dragOffset
  
          return CGPoint(x: 0, y: yOffset)
      }
  
      /* Return true so that the layout is continuously invalidated as the user scrolls */
      func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -&gt; Bool
      {
          return true
      }
  }
  </code></pre>
  
  <p>Here my Xcode project <a href="https://www.dropbox.com/sh/7xcu118a9zb7673/AAD6t5zhIgKC5fUUpUTb-yA1a?dl=0" rel="nofollow">https://www.dropbox.com/sh/7xcu118a9zb7673/AAD6t5zhIgKC5fUUpUTb-yA1a?dl=0</a></p>
  
  <p>Could you help me?</p>