//NSUserDeafult 图片的保存与读取

//NSUserDeafult保存图片数据到本地

-(void)saveImage:(UIImage *)image{

    NSData* data=[NSKeyedArchiver archivedDataWithRootObject:image];

    [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"xxxx"];数据保存到本地的Key

}

 

//读取NSUserDeafult保存到班底的图片数据

-(UIImage *)headImage{

    NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey:@"xxxx"];

    id image= [NSKeyedUnarchiver unarchiveObjectWithData:data];

    NSLog(@"image!:%@",image);

    if(image){

        return image;

    }

    return [UIImage imageNamed:@"YYYY"]本地没有读取到就返回默认图片

}

你可能感兴趣的:(//NSUserDeafult 图片的保存与读取)