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];
        }

  按钮的选中状态(选中一个,其他的变为未选中)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-03
  • 2022-01-25
  • 2021-11-22
  • 2021-11-22
  • 2021-09-22
猜你喜欢
  • 2021-11-16
  • 2021-11-22
  • 2021-11-30
  • 2021-08-24
  • 2021-11-22
  • 2021-11-22
  • 2022-12-23
相关资源
相似解决方案