我有一些关于 uibutton 的问题。我想要一个按钮在按下时突出显示,但在按下其他按钮时取消突出显示,但我无法让上一个按钮取消突出显示。有人可以请教吗?
@interface ViewController : UIViewController
{
UIButton *button1;
UIButton *button2;
}
@property (nonatomic, retain) IBOutlet UIButton *button1;
@property (nonatomic, retain) IBOutlet UIButton *button2;
-(IBAction)button1:(id)sender;
-(IBAction)button2:(id)sender;
-(void) highlightButton: (UIButton *) button;
-(void) unhighlightButton: (UIButton *) button;
@end
@interface ViewController ()
@end
@implementation ViewController
@synthesize button1, button2;
-(IBAction)button1:(id)sender
{
[self performSelector:@selector(highlightButton:) withObject:sender afterDelay:0.0];
[button2 performSelector:@selector(unhighlightButton:) withObject:button2 afterDelay:0.0];
}
-(IBAction)button2:(id)sender
{
[self performSelector:@selector(highlightButton:) withObject:sender afterDelay:0.0];
[button1 performSelector:@selector(unhighlightButton:) withObject:button1 afterDelay:0.0];
}
-(void) highlightButton:(UIButton *)button
{
[button setHighlighted:YES];
}
-(void) unhighlightButton:(UIButton *)button
{
[button setHighlighted:NO];
}
@end