ios 按钮单选框

- (IBAction)btnChoose:(id)sender {

    _btnConfirm.selected =YES;

    UIImage *selecticonNo =[UIImage imageNamed:@"未选中"];

    UIImage *selecticon =[UIImage imageNamed:@"选中"];

    UIButton *btn=nil;

    for (int i=1;i<REPORTNUMBER;i++) {

        btn = (UIButton *)[self.view viewWithTag:i];   //获取单选按钮  mainZone 是最外层的视图

        if ([btn isSelected]) {

            [btn setBackgroundImage:selecticonNo forState:UIControlStateNormal];

            [btn setSelected:NO];

        }

    }

    

    [sender setBackgroundImage:selecticon forState:UIControlStateSelected];

      [sender setSelected:YES];

    UIButton *btnSelected = nil;

    btnSelected = sender;

    reportType = [NSString stringWithFormat:@"%d",(int) btnSelected.tag];

    

}

如果出现选中状态旁边有蓝色,需设置选中状态。tintcolor为白色

你可能感兴趣的:(ios 按钮单选框)