1

如何将图像视图的突出显示状态保存为用户默认值,我可以将按钮的背景颜色保存为用户默认值吗?(我通过单击更改颜色)

保存:

- (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"];
        }
      }

装载:

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];
                      }

谢谢于尔根

4

0 回答 0