开发者

Set UIButton image and maintain transparency

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.


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

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

Hope this works for you as well... :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜