在手指触摸它/被拖动时更改UIButton尺寸

时间:2013-09-21 19:45:14

标签: ios objective-c cocoa-touch uibutton touch-event

我有一个可拖动的UIButton。我希望它在被拖动或触摸时有不同的背景图像。我想使用的图像是普通图像的两倍。我试过了正常的事情:

[button setBackgroundImage:buttonHighlightedImage forState:UIControlStateHighlighted];

但这不起作用。任何想法或提示将不胜感激。

1 个答案:

答案 0 :(得分:1)

这个怎么样:

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