title: Swift - How to use UIGraphics blend mode?
body: <p>I would like to develop a kind of progress bar animation for AppleWatch. 
  I decided to do it all with the <strong>UIGraphicContext</strong>. </p>
  
  <p>Since I'm a complete beginner I don't really understand how I can apply some kind of "<em>globalCompositeOperation</em>" to my context.</p>
  
  <p>To illustrate my idea better here are some pictures:</p>
  
  <p><img src="https://i.stack.imgur.com/Q85p4.png" alt="Image #1"></p>
  
  <p><img src="https://i.stack.imgur.com/foGKj.png" alt="Image #2"></p>
  
  <p><img src="https://i.stack.imgur.com/lMu8C.png" alt="Image #3"></p>
  
  <hr>
  
  <p>This is my source code so far:</p>
  
  <pre><code>let size = CGSize(width: 300, height: 100)
  UIGraphicsBeginImageContext(size)
  
  let context = UIGraphicsGetCurrentContext()!
  
  context.setFillColor(UIColor.red.cgColor)
  context.fill(CGRect(x: 0.0, y: 0.0, width: size.width * 0.5, height: size.height))
  context.setBlendMode(CGBlendMode.destinationOver)
  
  let count = 5;
  let padding = (size.width / CGFloat(count)) * 0.5
  for i in 0...count {
      let offsetX = size.width * (CGFloat(i) / CGFloat(count))
      let rect = CGRect(x: offsetX + padding/2, y: 0, width: padding, height: size.height)
      context.setFillColor(UIColor.green.cgColor)
      context.fill(rect)
  }
  UIGraphicsEndImageContext()
  </code></pre>
  
  <hr>
  
  <p>I guess this is kind of the wrong approach because the result is more like this:</p>
  
  <p><img src="https://i.stack.imgur.com/rvWwR.png" alt="Image #4"></p>
  
  <p>Any help would be really appreciated. Thanks in advance.</p>