Search code examples
objective-ccocoa-touchios6

UIButton show selected state on tap


How do I show the selected state for the UIButton on tap?

I want it so that when people tap on the uibutton it shows the selected state with the hover that I have?

Right now they have to hold the button to see the hover.

[t1 setBackgroundImage: [UIImage imageNamed: [NSString stringWithFormat: @"hover.png"]] forState:UIControlStateSelected];

I want to show the hover image on tap also.


Solution

  • You need to set the selected state for the button

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setImage:[UIImage imageNamed:@"hover.png"] forState:UIControlStateSelected];
    

    To show a hoover image while the button is pressed you need to set the state property to UIControlStateHighlighted