Skip to content

Instantly share code, notes, and snippets.

@ksm
Created February 20, 2012 16:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ksm/1869980 to your computer and use it in GitHub Desktop.
Save ksm/1869980 to your computer and use it in GitHub Desktop.
CALayer masking in drawLayer:inContext (to avoid layer.cornerRadius performance hit)
/*
Source: Apple Developer - Understanding iOS View Compositing
Note: setting view.layer.cornerRadius and .masksToBounds
sends the view for rending to an offscreen buffer.
We want to avoid unnecessary rendering passes.
Let the context do the work.
*/
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
CGRect rect = layer.bounds;
[[UIBezierPath bezierPathWithRoundedRect:rect
cornerRadius:10.0] addClip];
[image drawInRect:rect];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment