1

how can i save the highlighted state of a Image view to user defaults, and can i save the background Color of a Button to User defaults?(i change the color by click)

to save:

- (IBAction)char1_atheon_cp1_28:(id)sender {

        if(_char1_atheon_cp1_28_image.highlighted == NO)

        {


        _char1_atheon_cp1_28_image.highlighted = YES;
            _char1_atheon_cp1_28.backgroundColor =[UIColor greenColor];


        [[NSUserDefaults standardUserDefaults] setObject:UIImagePNGRepresentation([UIImage imageNamed:@"check.png"])forKey:@"char1_atheon_28_cp1"];
        }
        else
        {
        _char1_atheon_cp1_28_image.highlighted = NO;
        _char1_atheon_cp1_28.backgroundColor =[UIColor clearColor];
                 [[NSUserDefaults standardUserDefaults] setObject:UIImagePNGRepresentation([UIImage imageNamed:@"cross.png"])forKey:@"char1_atheon_28_cp1"];
        }
      }

to load:

if([[NSUserDefaults standardUserDefaults] objectForKey:@"char1_atheon_28_cp1"] != nil) {
                 NSData* imageData = [[NSUserDefaults standardUserDefaults]objectForKey:@"char1_atheon_28_cp1"];
        UIImage* image = [UIImage imageWithData:imageData];
        [_char1_atheon_cp1_28_image setImage:image];
                      }

Thanks Jürgen

Heisenberg
  • 113
  • 1
  • 8

0 Answers0