将突出显示状态保存到用户默认值

时间:2015-02-05 21:45:25

标签: iphone xcode image defaults

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

保存:

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

谢谢Jürgen

0 个答案:

没有答案