需要帮助在 iOS4 中的 uiview 中向图像添加阴影吗?

发布于 2024-09-15 10:08:24 字数 635 浏览 4 评论 0原文

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人如玉 2024-09-22 10:08:24

您是否考虑过使用 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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文