iOS 多个Button时,改变所点击Button的颜色,恢复其他Button的颜色

用UIButton类型的变量存储当前点击的Button、
判断一下下一次点击的Button和上次存储的是不是同一个button、
如果是同一个就不做处理、
如果不是就改变当前点击Button的颜色、
恢复上一个Button的颜色、

- (void)buttonClick:(UIButton *)sender{
if(_lastBtn== sender) {
    //上次点击过的按钮,不做处理
    } else{
      //本次点击的按钮设为红色
      [sender setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
      //将上次点击过的按钮设为黑色
      [_lastBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    _lastBtn = sender;
}

你可能感兴趣的:(iOS 多个Button时,改变所点击Button的颜色,恢复其他Button的颜色)