I've spent some time trying to figure out how to add a shadow to an NSView
. For now, I am attempting to use the NSShadow
class to accomplish this. My code is below. I am attempting to create the shadow in a custom init method in a NSView
subclass. No matter what I try, no shadow appears.
NSShadow *dropShadow = [[NSShadow alloc] init];
[dropShadow setShadowColor:[NSColor blackColor]];
[self setWantsLayer:YES];
[self setShadow:dropShadow];
Edit
Here is how I tried to do it with CALayer
.
self.layer.shadowOffset = CGSizeMake(10, 10);
self.layer.shadowOpacity = 1.0;
self.layer.shadowRadius = 10.0;
self.layer.shadowPath = [self quartzPathFromBezierPath:[NSBezierPath bezierPathWithRect:frame]];
quartzPathFromBezierPath:
converts an NSBezierPath
to a CGPath
.