需要帮助在iOS 4的uiview中为图像添加阴影?

时间:2010-08-22 03:17:26

标签: iphone uiimage shadowing

我正在尝试为图像创建投影。我还在视图之间有动画,这是背景。但是,当我使用以下代码时,不会绘制图像。有人有什么想法吗?

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);

1 个答案:

答案 0 :(得分:2)

您是否考虑过使用CALayer的阴影属性?例如,您可以执行以下操作:

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

点击此处了解更多信息:http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/occ/instp/CALayer/shadowColor