如果我在 Photoshop 中创建不透明度为 85% 的 PNG 图像,当我将其添加到 iOS 应用程序时,如何保持相同的不透明度水平?

发布于 2024-10-01 09:02:16 字数 330 浏览 4 评论 0原文

如果我在 Photoshop 中创建一个 PNG 图像并降低不透明度,使其不透明 85%,那么当我将其添加到 iOS 应用程序时,如何保持相同的透明度?

我试图将 UILabel 的背景图像设置为此图像,但 UILabel 的背景图像在我的 iOS 应用程序中完全不透明。这是我的代码...

[lbl setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"labelBackground.png"]]];

我错过了什么还是这是不可能的?

非常感谢您的智慧!

If I create a PNG image in Photoshop and lower the opacity so it's 85% opaque, how can I maintain that same level of transparency when I add it to my iOS app?

I'm trying to set the background image of a UILabel to be this image, but the background image for the UILabel is fully opaque in my iOS app. Here's my code...

[lbl setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"labelBackground.png"]]];

Am I missing something or is this not possible?

Thanks so much for your wisdom!

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

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

发布评论

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

评论(4

少女七分熟 2024-10-08 09:02:16

如果我是您,我会将包含图像的 UIImageView 放在您的 UILabel 后面。然后确保您的 UILabel 和 UIImageView backgroundColors 都设置为 [UIColor clearColor]。无论如何,我就是这么做的。

If I were you, I'd put an UIImageView containing the image behind your UILabel. Then make sure your UILabel and UIImageView backgroundColors are both set to [UIColor clearColor]. That's how I do it anyway.

她如夕阳 2024-10-08 09:02:16

您尝试过lbl.opaque = NO;吗?

Have you tried lbl.opaque = NO;?

高冷爸爸 2024-10-08 09:02:16

根据我的经验,iOS 保留 PNG 图像的不透明度。

我想我知道什么可能是错误的(请原谅我做出任何错误的假设)...

在 Photoshop 中,保存 PNG 图像时,有一个选项“保存透明度”或类似的选项。确保在保存 PNG 之前选中该选项。

如果这不是问题,您可以随时使用:

UIImageView.opacity = 85.0f/100.0f;

让我知道这是否可以解决您的问题:)

From my experience, iOS preserves opacity for PNG images.

I think I have an idea of what MAY be wrong (and pardon me for making any wrong assumptions)...

In photoshop, when saving a PNG image, there's an option to "Save Transparency" or something like that. Make sure that is checked before you save the PNG.

If this is not the problem, you can always use:

UIImageView.opacity = 85.0f/100.0f;

Let me know if this solves your problem :)

你怎么这么可爱啊 2024-10-08 09:02:16

我像你一样遇到了一些背景问题,但我了解到大多数 UIView 子类都有一个 backgroundView 属性,可以这样访问:

[aView backgroundView];

或者

aView.backgroundView = someView;

UIImageViews 保持图像的不透明度。记住这两件事,您就可以这样做:

UIImageView *imageView = [UIImageView initWithImage:[UIImage imageNamed:@"YourImage.png"]];

myLabel.backgroundColor = [UIColor clearColor];

myLabel.backgroundView = imageView;

我希望您发现这很有用。

I ran into some background issues just like you, but I learned that most UIView subclasses have a backgroundView property which is accessed like this:

[aView backgroundView];

or

aView.backgroundView = someView;

UIImageViews keep the opacity of images. With these two things in mind you can just do:

UIImageView *imageView = [UIImageView initWithImage:[UIImage imageNamed:@"YourImage.png"]];

myLabel.backgroundColor = [UIColor clearColor];

myLabel.backgroundView = imageView;

I hope you find this useful.

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