UIButton在按下时突出显示

时间:2012-06-06 01:37:30

标签: iphone ios xcode

我有两个UIButtons。按下时我能够突出显示它们。 :

-(IBAction) button1Pressed:(id)sender {

    [self performSelector:@selector(highlightButton1:) withObject:sender afterDelay:0.0];
}

- (void)highlightButton1:(UIButton *)a { 
    [a setHighlighted:YES];
}

-(IBAction) button2Pressed:(id)sender {

    [self performSelector:@selector(highlightButton2:) withObject:sender afterDelay:0.0];
}

- (void)highlightButton2:(UIButton *)b { 
    [b setHighlighted:YES];
}

我希望在突出显示其他按钮时取消突出显示按钮。 但我不能让它发挥作用。

1 个答案:

答案 0 :(得分:2)

如果您确实将按钮定义为:

IBOutlet NSButton * mode1;
IBOutlet NSButton * mode2;

然后你可以这样做:

- (void)highlightButton1:(UIButton *)a { 
    [mode1 setHighlighted:YES];
    [mode2 setHighlited:NO];
}

- (void)highlightButton2:(UIButton *)b { 
    [mode1 setHighlighted:NO];
    [mode2 setHighlited:YES];
}

参数a&在这种特殊情况下,b被忽略......