0

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.

Mason
  • 6,893
  • 15
  • 71
  • 115
  • I havent had chance to try and implement this to see how good it is/if its fully what youre looking for, but what about this? http://stackoverflow.com/questions/6939866/uiview-animation-change-size-of-button – Michael M Sep 21 '13 at 20:15

1 Answers1

1

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];
            }
Josh Wood
  • 203
  • 1
  • 2
  • 5
  • You need to resize the button's frame to fit the new image, but this answer works. Thanks! – Mason Sep 21 '13 at 23:38