Q:

Can't change background image of custom uiButton for selected state

With my code below, it seems that button is in normal state all the time (always green) eventhough i click on him.
UIButton *gumb = [UIButton buttonWithType:UIButtonTypeCustom];
     gumb.frame = CGRectMake(4, 40, 104, 37);
     gumb.tag=0;
    [gumb setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [gumb setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
    [gumb setBackgroundImage:[UIImage imageNamed:@"greenButton.png"] forState:UIControlStateNormal];
     [gumb setBackgroundImage:[UIImage imageNamed:@"whiteButton.png"] forState: UIControlStateSelected];

If i set image for normal state to whiteButton and for seleted to greenButton then the button is always white and never green.

A:

[gumb setBackgroundImage:[UIImage imageNamed:@"whiteButton.png"] forState: UIControlStateHighlighted] 

use this one instead  of selected image

A:

Do you set the state of the button as selected in the button click action
- (IBAction)buttonClicked:(id)sender;
{
UIButton *button = (UIButton *)sender;
if(button.tag == 0)// in your case
{
button.selected = YES;
}
// Do something
}

Hope this helps

