title: Applying Blend Modes in Swift
body: <p>What I'm trying to do is convert <a href="https://s3.amazonaws.com/f.cl.ly/items/0W3N3B3L2N1w0z2O1J2u/Image%202015-07-06%20at%205.00.22%20AM.png" rel="nofollow noreferrer">this</a> icon with solid white background into <a href="https://s3.amazonaws.com/f.cl.ly/items/311l2I3H202p1j1Y0127/Image%202015-07-06%20at%204.08.18%20AM.png" rel="nofollow noreferrer">this</a> icon with blended background.</p>
  
  <p>The background behind the icon is not really important, what I'm trying to achieve is the effect applied to the icon. The icon was created by using the <code>Soft Light</code> blend mode in Photoshop. I want to recreate that in iOS.</p>
  
  <p>This is the code I've tried, inspired by <a href="https://stackoverflow.com/a/14169247/5084415">this comment</a>:</p>
  
  <pre><code>@IBOutlet weak var cogButton: UIButton!
  
  func applyCogBackground() {
      UIGraphicsBeginImageContextWithOptions(cogButton.frame.size, false, 1)
      var context = UIGraphicsGetCurrentContext()
      view.drawViewHierarchyInRect(cogButton.bounds, afterScreenUpdates: false)
      UIImage(named: "Cog")?.drawInRect(cogButton.bounds, blendMode: kCGBlendModeSoftLight, alpha: 1)
      var result = UIGraphicsGetImageFromCurrentImageContext()
      UIGraphicsEndImageContext()
      cogButton.setBackgroundImage(result, forState: .Normal)
  
  }
  </code></pre>
  
  <p>I'm using <code>drawHierarchyInRect()</code> instead of <code>CALayer.renderInContext()</code> because I've been told it is much faster performance wise. Regardless, either ways both end up with the same result. The icon is unaltered (it retains its solid white background). What am I doing wrong?</p>