Skip to content

Instantly share code, notes, and snippets.

@mgcrea
Created August 15, 2012 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgcrea/3363043 to your computer and use it in GitHub Desktop.
Save mgcrea/3363043 to your computer and use it in GitHub Desktop.
UIBezierPath *buttonPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:self.layer.cornerRadius];
CAShapeLayer* shadowLayer = [CAShapeLayer layer];
//shadowLayer.cornerRadius = 8.0f;
[shadowLayer setOpacity:1];
[shadowLayer setBackgroundColor:UIColor.redColor.CGColor];
// Standard shadow stuff
[shadowLayer setShadowOpacity:1.0f];
[shadowLayer setShadowColor:[[UIColor colorWithWhite:1 alpha:1] CGColor]];
[shadowLayer setShadowOffset:CGSizeMake(2.0f, 2.0f)];
[shadowLayer setShadowRadius:5];
// Causes the inner region in this example to NOT be filled.
[shadowLayer setFillRule:kCAFillRuleEvenOdd];
// Create the larger rectangle path.
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, CGRectInset(self.bounds, -42.0f, -42.0f));
// Add the inner path so it's subtracted from the outer path.
CGPathAddPath(path, NULL, buttonPath.CGPath);
CGPathCloseSubpath(path);
[shadowLayer setPath:path];
CGPathRelease(path);
[self.layer addSublayer:shadowLayer];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment