title: Applying a CAShapeLayer mask to a UIView
body: <p>I am using this code to apply a layer to a UIview:</p>
  
  <pre><code>mask = [[CAShapeLayer alloc] init];
  mask.frame = baseView.layer.bounds;
  CGRect biggerRect = CGRectMake(mask.frame.origin.x, mask.frame.origin.y, mask.frame.size.width, mask.frame.size.height);
  CGRect smallerRect = CGRectMake(0.0f, 0.0f, 0.0f, 0.0f);
  
  UIBezierPath *maskPath = [UIBezierPath bezierPath];
  [maskPath moveToPoint:CGPointMake(CGRectGetMinX(biggerRect), CGRectGetMinY(biggerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMinX(biggerRect), CGRectGetMaxY(biggerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMaxX(biggerRect), CGRectGetMaxY(biggerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMaxX(biggerRect), CGRectGetMinY(biggerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMinX(biggerRect), CGRectGetMinY(biggerRect))];
  
  [maskPath moveToPoint:CGPointMake(CGRectGetMinX(smallerRect), CGRectGetMinY(smallerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMinX(smallerRect), CGRectGetMaxY(smallerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMaxX(smallerRect), CGRectGetMaxY(smallerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMaxX(smallerRect), CGRectGetMinY(smallerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMinX(smallerRect), CGRectGetMinY(smallerRect))];
  
  mask.path = maskPath.CGPath;
  [mask setFillRule:kCAFillRuleEvenOdd];
  mask.fillColor = [[UIColor blackColor] CGColor];
  baseView.layer.mask = mask;
  </code></pre>
  
  <p>Since the rectangle I want to cut changes, I was wonderning if there was a quick way to change the size of the mask instead of just removing it from the UIview and re-applying it with different dimensions:</p>
  
  <p>e.g.</p>
  
  <pre><code>[mask removeFromSuperlayer];
  </code></pre>
  
  <p>and...</p>
  
  <pre><code>mask = [[CAShapeLayer alloc] init];
  mask.frame = baseView.layer.bounds;
  CGRect biggerRect = CGRectMake(mask.frame.origin.x, mask.frame.origin.y, mask.frame.size.width, mask.frame.size.height);
  CGRect smallerRect = CGRectMake(0.0f, 100.0f, 200.0f, 200.0f);
  
  UIBezierPath *maskPath = [UIBezierPath bezierPath];
  [maskPath moveToPoint:CGPointMake(CGRectGetMinX(biggerRect), CGRectGetMinY(biggerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMinX(biggerRect), CGRectGetMaxY(biggerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMaxX(biggerRect), CGRectGetMaxY(biggerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMaxX(biggerRect), CGRectGetMinY(biggerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMinX(biggerRect), CGRectGetMinY(biggerRect))];
  
  [maskPath moveToPoint:CGPointMake(CGRectGetMinX(smallerRect), CGRectGetMinY(smallerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMinX(smallerRect), CGRectGetMaxY(smallerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMaxX(smallerRect), CGRectGetMaxY(smallerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMaxX(smallerRect), CGRectGetMinY(smallerRect))];
  [maskPath addLineToPoint:CGPointMake(CGRectGetMinX(smallerRect), CGRectGetMinY(smallerRect))];
  
  mask.path = maskPath.CGPath;
  [mask setFillRule:kCAFillRuleEvenOdd];
  mask.fillColor = [[UIColor blackColor] CGColor];
  baseView.layer.mask = mask;
  </code></pre>