title: Apply fade effect to top and bottom of UICollectionView
body: <p>I've read examples around here but I cannot do it the way I desire, somehow my gradient examples are stuck on the middle of the screen, not working as expected.</p>
  
  <p>I have a <code>UICollectionView</code> which fills the whole screen with vertical scroll.</p>
  
  <p>I want the top and bottom of the <code>UICollectionView</code> to be black and the middle to be transparent (since I'm using a black blackgroundColor).</p>
  
  <p>I tried to apply gradients, but somehow I'm failing to accomplish what I want. </p>
  
  <p>Here's my code:</p>
  
  <pre><code>let gradient = CAGradientLayer()
  gradient.frame = view.bounds
  gradient.colors = [UIColor.black.cgColor, UIColor.clear.cgColor, UIColor.black.cgColor]
  gradient.startPoint = CGPoint(x: 1, y: 0)
  gradient.endPoint = CGPoint(x: 1, y: 1)
  view.layer.mask = gradient
  </code></pre>
  
  <p>The code above is placing the gradient in the middle of the screen but inverted. It is transparent on top and bottom of the screen and the middle section if fading to complete black.</p>
  
  <p>I'm trying to create something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/3IGix.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3IGix.jpg" alt="img"></a></p>
  
  <p>Thanks for helping</p>