简体   繁体   中英

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.

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];
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM