Mason
Mason

Reputation: 7103

Change UIButton size while finger is touching it/while it's being dragged

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

Answers (1)

Josh Wood
Josh Wood

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

Related Questions