设置 UILabel 的背景(.png 文件的透明度问题)
我试图通过设置 UILabel 的属性 backgroundColor
来设置 UILabel 的背景。
但我有一个问题:backgroundColor 是从 .png 文件(具有透明度)创建的,结果是透明部分显示为黑色。
有没有不需要自定义子类的解决方案?
更新
我尝试将 UILabel 属性 opaque
设置为 NO
但问题仍然存在。
I'm trying to set the background of a UILabel by setting its property backgroundColor
.
But I have a problem: the backgroundColor is created from a .png file (with transparency) and the result is that the transparent part appear in black.
Any solution without the need of custom subclasses?
Update
I tried setting the UILabel property opaque
to NO
but the problem is still there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
听起来您可能忘记更改 UILabel 的 opaque 属性:
或者,您可以在 Xcode 的 InterfaceBuilder 视图中设置此属性。
It sounds like you might have forgotten to change the opaque property of the UILabel:
Alternatively, you can set this property in the InterfaceBuilder view of Xcode.
我遇到了同样的问题,解决方案是:
更改不透明或 alpha 值不起作用。
I had the same problem, and the solution is:
Changing opaque or alpha value didn't work.
也许你可以尝试这个:
Maybe you can try this one:
您还需要将其保存为 png24 或 24 位 png 文件 - 至少从 PhotoShop 保存时是这样
You'll also need to save it as a png24 or 24bit png file - at least that's the case when saving from PhotoShop
一定是工作,祝你好运!
it must be work,goodLuck!
将其
opaque
属性更改为NO
。如果没有帮助,您可以在标签后面添加 imageView:
Change its
opaque
property toNO
.If it doesn't help, you can add imageView behing your label: