ios - 图像复选框问题

标签 ios objective-c checkbox

当我第二次选中该复选框时,它会显示已选中的图像,但状态为未选中。

这是我的代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    [CheckBox setBackgroundImage:[UIImage imageNamed:@"uncheck_checkbox.png"] forState:UIControlStateNormal];
}

- (IBAction)CheckBox:(id)sender {

    if (CheckBox.selected == NO)
    {
          CheckBox.selected = YES;
          [CheckBox setBackgroundImage:[UIImage imageNamed:@"checked_checkbox.png"] forState:UIControlStateNormal];       
    }
    else
    {
          CheckBox.selected = NO;
          [CheckBox setBackgroundImage:[UIImage imageNamed:@"uncheck_checkbox.png"] forState:UIControlStateSelected];     
    }
}

最佳答案

您的代码完全正确,只需将 UIControlStateSelected 替换为 UIControlStateNormal

关于ios - 图像复选框问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34390294/

相关文章:

ios - 将http请求转成json

ios - 使用 iCloud Apple ID 匿名登录应用程序

objective-c - iOS 7.1 imagePicker CameraFlashMode 不指示开/关状态

ios - 如何在 NSOperationQueue 完成之前阻止 NSOperation?

apache-flex - AS3 中的 Flex 绑定(bind) - 否定 boolean 值

javascript - 警告所有在 ng-Repeat : AngularJS 中选中的复选框

c# - WPF 复选框 : Check changed handling

ios - 在 ARKit 框架中设置光照

c++ - 带有 pthreads 的后台线程

ios - UIViewControllerAnimatedTransitioning 与自定义 UIStoryboardSegue