2014-06-29 74 views

回答

1

使用setSelected:更改按鈕的選擇狀態。

在viewDidLoad中

[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; 
    } 
} 
0

應該像這樣:

- (IBAction)aButtonClicked:(id)sender { 
    [aButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; 
} 

- (IBAction)bButtonClicked:(id)sender { 
    [aButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
}