Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CheckBox issues with images

When I select the check box the second time it shows me the checked image, but the status is unchecked.

Here is my code:

- (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];     
    }
}
like image 795
Pooja Puri Avatar asked Dec 25 '22 11:12

Pooja Puri


1 Answers

Your code is totally right just you replace UIControlStateSelected to UIControlStateNormal.

like image 70
Mitul Marsoniya Avatar answered Dec 28 '22 08:12

Mitul Marsoniya