I have a UIView
that programmatically draws a "sunburst" pattern using UIBezierPath
. Now I would like to extend this by masking the edges with a gradient -- effectively making each "burst" fade from opaque to transparent. I'm think this could be done with a CAGradientLayer
mask but I'm not sure how to make it circular.
This is what I'm trying -- it masks the view but the gradient is linear:
CAGradientLayer *l = [CAGradientLayer layer];
l.frame = CGRectMake(0.0f, 0.0f, rect.size.width, rect.size.height);
l.cornerRadius = rect.size.width/2.0f;
l.masksToBounds = YES;
l.colors = [NSArray arrayWithObjects:(id)[UIColor blackColor].CGColor, (id)[UIColor clearColor].CGColor, nil];
self.layer.mask = l;
I'm open to not using CAGradientLayer
if anyone knows any other ways to mask a view with a circle with blurred edges.
SOLUTION
Thanks to matt's insight, I ended up drawing a mask view using CGContextDrawRadialGradient
, rendering that as a UIImage
, and using that as a mask layer. If anyone is interested in this process, it is being used in this test project.