title: Gradient over UIImageView
body: <p>I've been trying to fill an image view with a gradient layer, but I can't seem to make it work, I tried to create CAGradientLayer, applied 2 colors on it then applied it as a mask to the main image layer.</p>
  
  <pre><code>let gradient = CAGradientLayer()
  gradient.frame = (self.imageView?.bounds)!
  gradient.colors = [UIColor.blue.cgColor, UIColor.purple.cgColor]
  gradient.startPoint = CGPoint(x: 0.0, y: 0.5)
  gradient.endPoint = CGPoint(x: 0.5, y: 1.0)
  gradient.locations = [0, 1]
  self.imageView?.layer.mask = gradient
  </code></pre>
  
  <p>This is what I have, and this is what I want as a result:</p>
  
  <p><img src="https://i.stack.imgur.com/5JZVG.png" alt="First"> <img src="https://i.stack.imgur.com/myHNS.png" alt="Second"></p>
  
  <p>UPDATE:
  Found the solution <a href="https://stackoverflow.com/questions/8098130/how-can-i-tint-a-uiimage-with-gradient">here</a>.</p>