一、(推荐)
定义一个UIButton *currenctButton;
- (IBAction)ButtonAction:(UIButton *)sender{
if (sender != currentButton)
{
currentButton.selected = NO;
currentButton = sender;
}
currentButton.selected = YES;
}
二、
先定义个全局的UIButton* _tmpBtn ,让它指向nil
所有button 指向同一个点击事件;
-(void)buttonSeclected:(UIButton *)btn withTag:(NSInteger)tag{
if (_tmpBtn == nil){
btn.selected = YES;
_tmpBtn = btn;
}
else if (_tmpBtn !=nil && _tmpBtn == btn){
btn.selected = YES;
}
else if (_tmpBtn!= btn && _tmpBtn!=nil){
_tmpBtn.selected = NO;
btn.selected = YES;
_tmpBtn = btn;
}
}