I want to be able to change the image of any of the buttons upon the user pressing the button and then when they release, the image that was there before is put back.
So basically when they press their finger on the button, the image changes and when they release, the original image I specified in IB is put back.
How can I do this? Here is the code I have so far.
- (IBAction)btnOne:(id)sender {
result.text = [self appendresult:@"1"];
//Changes the button image upon touch
[btnOne setImage:[UIImage imageNamed:@"NumberBtn1.png"] forState:UIControlStateNormal];
[btnOne setImage:[UIImage imageNamed:@"NumberBtn1Alt.png"] forState:UIControlStateHighlighted];
[btnOne setImage:[UIImage imageNamed:@"NumberBtn1Alt.png"] forState:UIControlStateSelected];
btnOne.showsTouchWhenHighlighted = YES;
}
Put your code...
[btnOne setImage:[UIImage imageNamed:@"NumberBtn1.png"] forState:UIControlStateNormal];
[btnOne setImage:[UIImage imageNamed:@"NumberBtn1Alt.png"] forState:UIControlStateHighlighted];
[btnOne setImage:[UIImage imageNamed:@"NumberBtn1Alt.png"] forState:UIControlStateSelected];
btnOne.showsTouchWhenHighlighted = YES;
in viewDidLoad
instead of in the IBAction
, then just make sure that your button in Interface Builder
is properly linked to the IBOutlet
you created for it.