简体   繁体   中英

Need help in adding a drop shadow to an image in a uiview in iOS4?

I am trying to create a drop shadow for an image. I also have an animation between views and this is the backdrop. However, when I use the following code, the image is not drawn. Anyone have any ideas?

self.frontViewBackground = [[[UIView alloc] initWithFrame:frame] autorelease];
//self.frontViewBackground.image = [UIImage imageNamed:@"whitepaper3.png"];
self.frontViewBackground.multipleTouchEnabled = YES;
[self.photoView addSubview:self.frontViewBackground];

UIImage *image = [UIImage imageNamed:@"whitepaper3.png"]; 

CGContextRef ctx = UIGraphicsGetCurrentContext();

CGContextSetShadow(ctx, CGSizeMake(1, -2), 3.0);
[image drawInRect:self.frontViewBackground.frame blendMode:kCGBlendModeNormal alpha:1.0];
CGContextRestoreGState(ctx);

Have you thought about using CALayer's shadow properties? For example you could do the following:

UIView *view = [[UIView alloc] initWithFrame:frame];
view.layer.shadowColor = [[UIColor blackColor] CGColor];
view.layer.shadowRadius = 5.0

Check out more here: http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/occ/instp/CALayer/shadowColor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM