cocoashadownsimagenscell

Draw shadow under NSImage


Currently I'm drawing an NSImage in a custom NSCell like so:

- (void)drawInteriorWithFrame:(NSRect)theCellFrame inView:(NSView *)theControlView {
    // roundedCornerImage creates a new NSImage with rounded corners, rather than clipping.
    [[anIcon roundedCornerImage:5] drawInRect:anIconBox fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
}

Very simply I'm wondering how to draw an image underneath it. On the iPhone, I would do this by using: CGContextSetShadow (currentContext, CGSizeMake(1, -1), 2); just before drawing the UIImage, but I'm unfamiliar with how to do it on the Mac.

Any pointers would be great.


Solution

  • Look into the NSShadow class. CGContextSetShadow also exists on the Mac, but it's slightly more difficult to get your hands on the context itself.