title: Draw gradient under UIBezierPath
body: <p>I have drawn a curved line. I want to put a gradient from the view all the way up to the line (so that the gradient curves along with the line.)</p>
  
  <p>edit: here is a photo of what the code below produces: </p>
  
  <p><a href="https://i.stack.imgur.com/gfNLo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gfNLo.png" alt="enter image description here"></a></p>
  
  <p>I know how to draw the line, and I know how to add a regular gradient, but just not the two together. Here is my code:</p>
  
  <pre><code>override func drawRect(rect: CGRect) {
  
      // draw the curved line, this code works just fine.
      let path1 = UIBezierPath()
      path1.lineWidth = 1.1
      UIColor.greenColor().setStroke()
      path1.moveToPoint(CGPoint(x: 0, y: bounds.height/2))
      path1.addQuadCurveToPoint(CGPoint(x: bounds.width, y: bounds.height/2), controlPoint: CGPoint(x: bounds.width/2, y: (bounds.height * 0.75)))
      path1.stroke()
  
      // my attempt to draw the gradient:
  
      let gradient = CAGradientLayer()
      gradient.startPoint = CGPoint(x: 1, y: 1)
      gradient.endPoint = CGPoint(x: 0, y: 0)
      let colors = [UIColor.whiteColor().CGColor, UIColor(red: 0, green: 1, blue: 1, alpha: 0.4).CGColor]
      gradient.colors = colors
  
      // the following line is where I need help
      gradient.frame = CGRectMake(0, 475, bounds.width, path1.bounds.height)
  
      layer.addSublayer(gradient)
  
  
  }
  </code></pre>
  
  <p>what can I set gradient.frame equal to so that it's upper limit is the previously drawn path? Answer in Swift please (i've seen a lot of other questions on this subject but they are all in objective C)</p>
  
  <p>Thanks</p>