English 中文(简体)
设置UIButton图像并保持透明度
原标题:Set UIButton image and maintain transparency

我有一个UIButton(设置为“自定义”类型)。如果我在界面生成器中设置了图像,则图像将以透明的方式正确显示。但是,如果我试图在应用程序运行时以编程方式设置它(例如,更改按钮上显示的图像),透明度就不会正确显示——相反,我会得到图像的白色背景。

以下是我在代码中设置按钮图像的方式:

[die1Button setImage:[UIImage imageNamed:die1.dieImage] forState:UIControlStateNormal];

非常感谢任何想法。

最佳回答

Xcode记得以前版本的图像,那些没有透明度的图像——尽管我添加了带有透明度的新版本。我不得不做一个产品清洁,现在一切都如预期。

问题回答

您正在使用的方法将图像放在按钮的前景上。我使用了以下方法,效果很好

[die1Button setBackgroundImage:[UIImage imageNamed:@"yourImageName.png"] forState:UIControlStateNormal];

希望这也适用于你…:)





相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签