UIView背景图片透明度问题

发布于 2024-11-18 05:45:53 字数 584 浏览 3 评论 0原文

我添加了一个带有 PNG 图像的子视图,该图像应该以透明度显示,但我在透明度应该是的地方变得全黑。

代码是:

- (void)viewDidLoad
{
    [super viewDidLoad];
    toolbar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"BannerBackground.png"]];
    logoImage = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 56)];
    logoImage.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Logo.png"]];
    [self.view addSubview:logoImage];

}

这是适用于 iPad、iOS 版本 4.3 的代码。我在模拟器和 iPad 上都遇到同样的问题。

由于这是最后添加的视图,我希望它的 az 索引高于所有其他视图,因此其他视图应通过透明区域显示。这是行不通的。

I added a subview with an PNG image that should display with transparency, but I am getting all black where the transparency should be.

The code is:

- (void)viewDidLoad
{
    [super viewDidLoad];
    toolbar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"BannerBackground.png"]];
    logoImage = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 56)];
    logoImage.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Logo.png"]];
    [self.view addSubview:logoImage];

}

This is code for a iPad, iOS version 4.3. I have the same problem with both the simulator and the iPad.

Since this is the last view added, I expect it to have a z index higher than all of the other views, so the other views should show through the transparent areas. This is not working.

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

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

发布评论

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

评论(6

蓝天白云 2024-11-25 05:45:53

我注意到这在 iOS 4.3.x 上的行为与 5.0 不同.x。在 4.3.x 中,我必须将不透明设置为 YES,然后设置背景图像,然后将其设置回 NO。

I noticed this behaves differently on iOS 4.3.x than 5.0.x. In 4.3.x I had to set opaque to YES, then set the background image, then set it back to NO.

寄风 2024-11-25 05:45:53

将视图的属性不透明设置为否。像这样 [view setOpaque:NO];

Set your view's property opaque to no. like this [view setOpaque:NO];

安穩 2024-11-25 05:45:53

失败 setOpaque:NO...检查您的图像是否正确导出并且没有损坏等...这发生在我身上一次

Failing setOpaque:NO... check to see if your image is correctly exported and not corrupted etc.. that happened to me once

帅气尐潴 2024-11-25 05:45:53

创建一个具有透明背景颜色和您的徽标作为图像的 UIImageView,并添加:

UIImageView *logoView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"Logo.png"]];
logoView.backgroundColor = [UIColor clearColor];
[self.view addSubview:logoView];

Create a UIImageView with transparent backgroundColor and your logo as its image, and add that:

UIImageView *logoView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"Logo.png"]];
logoView.backgroundColor = [UIColor clearColor];
[self.view addSubview:logoView];
欢你一世 2024-11-25 05:45:53

这应该有效。

#import <QuartzCore/QuartzCore.h>



logoImage = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 56)];
logoImage.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Logo.png"]];
[logoImage.layer setOpaque:NO];
logoImage.opaque = NO;


[self.view addSubview:logoImage];

This should work.

#import <QuartzCore/QuartzCore.h>



logoImage = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 56)];
logoImage.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Logo.png"]];
[logoImage.layer setOpaque:NO];
logoImage.opaque = NO;


[self.view addSubview:logoImage];
梦幻的味道 2024-11-25 05:45:53

老问题,但是:你的透明度是否有可能是黑色的,而不是真正透明的?并不是说我刚刚做了那件事或其他什么事情。

(绘制工具栏图标时,iOS 会用白色填充所有像素,包括黑色像素。确保您期望的透明区域实际上没有任何内容。)

Old question, but: any chance that your transparency is, for instance, black and not actually transparent? Not that I just did that or anything.

(When drawing the toolbar icon, iOS fills in any pixels, including black ones, with white. Make sure there's actually nothing where you expect your transparent area to be.)

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