title: drawing gradient over rectangle in swift
body: <p>I try to draw a gradient in a rectangle. 
  Following picture shows, that gradient in general works (blue), but it fills the entire screen. </p>
  
  <p>I like to do the gradient only in a specific area like the green rectangle. </p>
  
  <p>How can I do this ?</p>
  
  <p><img src="https://i.stack.imgur.com/6FcKt.jpg" alt="enter image description here"></p>
  
  <p>My code for the gradient experiment :-)</p>
  
  <pre><code>let context = UIGraphicsGetCurrentContext()
  
  //let locations: [CGFloat] = [ 0.0, 0.25, 0.5, 0.75 ]
  let locations: [CGFloat] = [ 0.0, 0.99 ]
  
  let colors = [UIColor.blueColor().CGColor,
                 UIColor.whiteColor().CGColor]
  
  let colorspace = CGColorSpaceCreateDeviceRGB()
  
  let gradient = CGGradientCreateWithColors(colorspace,
      colors, locations)
  
  var startPoint = CGPoint()
  var endPoint =  CGPoint()
  
  startPoint.x = 0.0
  startPoint.y = 10.0
  endPoint.x = self.frame.width-100;
  endPoint.y = 10
  
  //let rectangle_main = CGRectMake(CGFloat(15), CGFloat(0), CGFloat(1000), CGFloat(30));
  
  //CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0)
  CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0)
  </code></pre>