I'm trying to draw a shadow under the bottom edge of a UIView
in Cocoa Touch. I understand that I should use CGContextSetShadow()
to draw the shadow, but the Quartz 2D programming guide is a little vague:
- Save the graphics state.
- Call the function
CGContextSetShadow
, passing the appropriate values. - Perform all the drawing to which you want to apply shadows.
- Restore the graphics state
I've tried the following in a UIView
subclass:
- (void)drawRect:(CGRect)rect {
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSaveGState(currentContext);
CGContextSetShadow(currentContext, CGSizeMake(-15, 20), 5);
CGContextRestoreGState(currentContext);
[super drawRect: rect];
}
..but this doesn't work for me and I'm a bit stuck about (a) where to go next and (b) if there's anything I need to do to my UIView
to make this work?