0
我想A按鈕改變從白色到紅色的titleColor當我點擊的UIButton:改變titleColor當點擊更改回來時otherButton點擊了
但是當我點擊另一個按鈕,我想A按鈕變回白色
我該怎麼做?
這是我寫的代碼,但它不工作,因爲我想。
[aButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
我想A按鈕改變從白色到紅色的titleColor當我點擊的UIButton:改變titleColor當點擊更改回來時otherButton點擊了
但是當我點擊另一個按鈕,我想A按鈕變回白色
我該怎麼做?
這是我寫的代碼,但它不工作,因爲我想。
[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];
}