MatthewExpungement
MatthewExpungement

Reputation: 93

UIButton is faded when pushed

I've set my UIButton normal state to one image and it's highlighted state to another. The button normal is fine but when I push the button down it sets it to a gray faded version of the image it's supposed to be. In the image below the top grayed out button is being pressed and the other buttons are in their normal state.The buttons are programmatically made.

UIButton *button;

UIImage *bluenormalImage = [UIImage imageNamed:@"bluebuttonnormal.png"];
UIImage *bluepressedImage = [UIImage imageNamed:@"bluebuttonpushed.png"];

[button setBackgroundImage:bluenormalImage forState:UIControlStateNormal];
[button setBackgroundImage:bluepressedImage forState:UIControlStateHighlighted];

top button is clicked

Upvotes: 1

Views: 248

Answers (1)

Sasha Reid
Sasha Reid

Reputation: 1547

OK, I didn't realise the text wasn't part of the image. Do this instead:

From what I can see you need to properly initialise the button as a custom type. The highlight issue occurs when the button type is system.

Change your button variable line to the following:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

If you initialise it later, you can do the following before you set the background image.

UIButton *button 
button = [UIButton buttonWithType:UIButtonTypeCustom];

Upvotes: 2

Related Questions