Created
February 21, 2012 11:20
-
-
Save ksm/1875946 to your computer and use it in GitHub Desktop.
CALayer shadowPath done the right way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Source: Apple Developer - Understanding iOS View Compositing | |
*/ | |
// setup the layer | |
CALayer *layer = view.layer; | |
layer.bounds = sublayer_bounds; | |
layer.backgroundColor = random_color(); | |
// set the shadow properties on the layer | |
layer.shadowOpacity = 0.5; | |
layer.shadowRadius = 10; | |
layer.shadowOffset = CGSizeMake(0, 10); | |
// get a UIBezierPath (for its CGPath gut) | |
CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:sublayer_bounds].CGPath; | |
sublayer.shadowPath = shadowPath; | |
// set the CGPath as the shadow layer | |
UIImage *image = [self loadImage]; | |
UIColor *color = [UIColor colorWithWhite:0 alpha:0.5]; | |
// Draw it into context (you always want to draw it into context, all in one rendering pass) | |
CGContextSetShadowWithColor(ctx, CGSizeMake(0,10) /* offset */, 10 /* blur radius */, color.CGColor); | |
CGContextDrawImage(ctx, r, image.CGImage); | |
the CGContext
you are drawing into. CGContextRef context = UIGraphicsGetCurrentContext();
What's the "r" in the CGContextDrawImage
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you clarify what ctx is?