我有一个可拖动的UIButton。我希望它在被拖动或触摸时有不同的背景图像。我想使用的图像是普通图像的两倍。我试过了正常的事情:
[button setBackgroundImage:buttonHighlightedImage forState:UIControlStateHighlighted];
但这不起作用。任何想法或提示将不胜感激。
答案 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];
}