title: Adding a mask with CALayers
body: <p>I seem to be having difficulties adding a mask via CALayers. I'm simply trying to mask a UIImageView. Here's my code:</p>
  
  <pre><code> CALayer *maskLayer = [CALayer layer];
   UIImage *mask = [UIImage imageNamed:@"mask.png"];
   maskLayer.contents = mask;
  
  UIImageView *viewToMask = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
  viewToMask.image = [UIImage imageNamed:@"picture.png"];
  viewToMask.layer.mask = maskLayer;
  [self.view addSubview:viewToMask];
  </code></pre>
  
  <p>Mask.png is black with a transparent circle punched through it (is this correct way to mask?). I'm not sure where this is failing, perhaps at <code>maskLayer.contents</code> since its supposed to be a <code>CGImageRef</code> but I get errors when I set it as <code>mask.CGImage</code>, or through a local variable <code>CGImageRef = mask.CGImage</code>. Anyway, the way its set now doesn't give errors, so I hope its fine.</p>
  
  <p>Does anyone know what's going on, or how to properly set masks with CALayers? Thanks</p>