Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton - On touch change image

When I touch the button at that time I want to change image & when i release the touch button image is as it is.

I want to apply below code but it's not with my expectation.

please give me any suggestion.....

   -(IBAction)actionEnter:(id)sender{
            if ([sender isSelected]) {
                [sender setImage:[UIImage imageNamed:@"enter-hover.png"] 
                        forState:UIControlStateNormal];
                [sender setSelected:NO];
            } else {
                [sender setImage:[UIImage imageNamed:@"enter.png"] 
                        forState:UIControlStateSelected];
                [sender setSelected:YES];
            }
like image 517
Sam007 Avatar asked Apr 18 '11 06:04

Sam007


1 Answers

You can use UIControlStateHighlighted for this.

[myButton setImage:[UIImage imageNamed:@"enter-hover.png"] 
          forState:UIControlStateHighlighted];

You can also set this from interface builder by setting the image for highlighted state.

like image 91
taskinoor Avatar answered Oct 11 '22 20:10

taskinoor