//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"]本地没有读取到就返回默认图片
}
时间: 2024-11-03 03:39:08