如何在 Objective C 中创建单选按钮

How to create Radio Buttons in Objective C

如何在 Objective 中制作单选按钮 c.I 想要在点击单选按钮时切换到不同的视图控制器。想做简单的两个单选按钮。

使用任何 UIButton 的选中/未选中状态。 使用 setImage:forState 分配选中/未选中的无线电图像/ 按下按钮时,遍历组的所有按钮并将适当的按钮设置为选中。

就是这样!

  1. 您需要在 ViewDidLoad 中为按钮设置不同的图像及其状态。

    [yourbutton setImage: [UIImage imageNamed:@"Radio_button_off.png"]forState:UIControlStateNormal];
    [yourbutton setImage: [UIImage imageNamed:@"Radio_button_on.png"]forState: UIControlStateSelected];
    
    - (void) btnAction:(UIButton*)button{
         button.selected = !button.selected;
    }