0

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

[button setBackgroundImage:buttonHighlightedImage forState:UIControlStateHighlighted];

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

4

1 回答 1

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];
            }
于 2013-09-21T23:02:33.073 回答