1、首先设定一个属性记录当前选中的按钮
/** * 记录当前选中的按钮 */ @property (nonatomic, weak) UIButton *selectedButton;
2、当点击按钮的时候改变按钮的选中状态
- (IBAction)goButton:(UIButton *)sender {
// 1、让当前选中的按钮取消选中
self.selectedButton.selected = NO;
//2、让新点击的按钮选中
sender.selected = YES;
//3、新点击的按钮就成了当前选中的按钮
self.selectedButton = sender;
NSLog(@"%ld",(long)sender.tag);
}
3、首次进入时如果有默认选中的按钮就加入下面 的代码:
//默认选中第一个按钮
if (i == 0) {
[self goButton:button];
}

原文:http://www.cnblogs.com/h-tao/p/5226838.html