Reputation: 7103
I have a draggable UIButton. I'd like for it to have a different background image while it's being dragged or touched. The image I would like to use is twice the size of the normal one. I've tried the normal:
[button setBackgroundImage:buttonHighlightedImage forState:UIControlStateHighlighted];
but that doesn't work. Any ideas or tips would be much appreciated.
Upvotes: 0
Views: 182
Reputation: 213
How about this:
[button addTarget:self action:@selector(btnTouch:)
forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(btnTouchCancel:)
forControlEvents:UIControlEventTouchCancel];
-(void)btnTouch:(id)sender{
UIButton *button=sender;
[button setBackgroundImage:buttonHighlightedImage forState:UIControlStateNormal];
}
-(void)btnTouchCancel:(id)sender{
UIButton *button=sender;
[button setBackgroundImage:buttonNormalImage forState:UIControlStateNormal];
}
Upvotes: 1