当我点击
时,我想让按钮的titleColor从白色变为红色但是当我点击其他按钮时,我想让按钮变回白色
我该怎么做呢?
这是我写的代码,但它不是我想要的工作。
[aButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
使用setSelected:
改变按钮的选择状态。
[aButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[aButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
[bButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[bButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
aButton.selected = YES;
- (IBAction)aButton_or_bButtonClicked:(id)sender {
if(aButton.selected) {
aButton.selected = NO;
bButton.selected = YES;
}
else {
aButton.selected = YES;
bButton.selected = NO;
}
}
应该是这样:
- (IBAction)aButtonClicked:(id)sender {
[aButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}
- (IBAction)bButtonClicked:(id)sender {
[aButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}