Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

buttons turn blue when backgroundimage is set

I have a few buttons and when I set a picture as background the icons turn blue, for example:

[self.button setImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];

All pictures are black and white, so I don't understand why they change their color when I set them as a backgroundimage.

like image 730
user2414460 Avatar asked Dec 13 '13 09:12

user2414460


People also ask

Can a trigger change the background color of a button?

This example uses a trigger to change the foreground color of the button when it is pressed, but will never change the background color.

How to change the background color of the document using JavaScript?

Given an HTML document and the task is to change the background color of the document using JavaScript and jQuery. Approach 1: This approach uses JavaScript to change the background color after clicking the button. Use HTML DOM Style backgroundColor Property to change the background color after clicking the button.

Can I change the background of a button while overwriting?

Whenever my pointer goes to a button, does not change the background of the button or even the foreground of the button, but it changes the background of the border. So, while overwriting the button style, actually the border of the background has to be overwritten and not the button foreground or the background.


1 Answers

Make sure to init the button as a "UIButtonTypeCustom"

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

Then if you want the whole button to be an image, you use:

[button setImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];

... Or if you want to have the image as the background, and still see the "title", you use:

 [button setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
like image 131
BlackMouse Avatar answered Sep 30 '22 13:09

BlackMouse