Skip to content

Instantly share code, notes, and snippets.

@yaozhuoyu
Forked from ksm/gist:1869980
Created September 1, 2013 16:32
Show Gist options
  • Save yaozhuoyu/6405550 to your computer and use it in GitHub Desktop.
Save yaozhuoyu/6405550 to your computer and use it in GitHub Desktop.
/*
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