UIImage Shadow Trouble

Posted by Brandon Schlenker on Stack Overflow See other posts from Stack Overflow or by Brandon Schlenker
Published on 2009-06-07T21:07:42Z Indexed on 2010/05/30 16:22 UTC
Read the original article Hit count: 476

Filed under:
|
|

I'm trying to add a small shadow to an image, much like the icon shadows in the App Store. Right now I'm using the following code to round the corners of my images. Does anyone know how I can adapt it to add a small shadow?

- (UIImage *)roundCornersOfImage:(UIImage *)source height:(int)height width:(int)width  {
int w = width;
int h = height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef imageContext = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);

CGContextBeginPath(imageContext);

CGRect rect = CGRectMake(0, 0, w, h);
addRoundedRectToPath(imageContext, rect, 10, 10);
CGContextClosePath(imageContext);
CGContextClip(imageContext);

CGContextDrawImage(imageContext, CGRectMake(0, 0, w, h), source.CGImage);

CGImageRef imageMasked = CGBitmapContextCreateImage(imageContext);
CGContextRelease(imageContext);
CGColorSpaceRelease(colorSpace);

return [UIImage imageWithCGImage:imageMasked];    
}

"addRoundedRectToPath" refers to another method that obviously rounds the corners.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk