设置UIButton图像并保持透明度
我有一个 UIButton(设置为“自定义”类型)。如果我在 Interface Builder 中设置图像,图像会正确显示,并且具有透明度。但是,如果我尝试在应用程序运行时以编程方式设置它(例如,更改按钮上显示的图像),透明度将无法正确显示 - 相反,我会得到图像的白色背景。
这就是我在代码中设置按钮图像的方式:
[die1Button setImage:[UIImage imageNamed:die1.dieImage] forState:UIControlStateNormal];
非常感谢任何想法。
I have a UIButton (set to type "Custom"). If I set the image in Interface Builder, the image is shown properly, with transparency. But if I try to set it programmatically while the App is running (for example, to change the image displayed on the button), the transparency isn't displayed correctly - instead I get a white background to the image.
This is how I'm setting the button's image in code:
[die1Button setImage:[UIImage imageNamed:die1.dieImage] forState:UIControlStateNormal];
Would hugely appreciate any ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Xcode 会记住图像的先前版本,即那些没有透明度的图像 - 尽管我添加了具有透明度的新版本。我必须做一个产品 - 清洁,现在一切都如预期的那样。
Xcode was remembering the previous version of the images, the ones without transparency - even though I had added the new versions with transparency. I had to do a Product - Clean and now it's all as expected.
您使用的方法将图像放在按钮的前景上。我使用了以下方法并且有效
希望这也适合您......:)
The method you are using puts the image on the foreground of the button. I used the following method and it worked
Hope this works for you as well... :)