我在任何地方都找不到关于这个的直接答案。所以我酿造了自己的解决方案,似乎效果很好。
不要忘记在IB中连接您的按钮,您需要将两者都绑定
touch up inside
到setButtonPressed
file owner
前button
。1stButton
伪代码
代码
//Declare your buttons in .h
UIButton *1stButton;
UIButton *2ndButton;
UIButton *3rdButton;
@property(nonatomic, retain) IBOutlet UIButton *1stButton;
@property(nonatomic, retain) IBOutlet UIButton *2ndButton;
@property(nonatomic, retain) IBOutlet UIButton *3rdButton;
//In .m file - write 2 methods
-(void)clearButtons
{
[1stButton setSelected:FALSE];
[2ndButton setSelected:FALSE];
[3rdButton setSelected:FALSE];
}
//attach to touch up inside event in IB for each button
-(void) setButtonPressed:(UIButton *)sender
{
self.clearButtons;
[sender setSelected:TRUE];
[sender setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
}