iOS圖片存在本地、再從本地擷取圖片,ios圖片存在擷取
圖片存在本地、再從本地擷取圖片
//將圖片儲存到本地+ (void)SaveImageToLocal:(UIImage*)image Keys:(NSString*)key { NSUserDefaults* preferences = [NSUserDefaults standardUserDefaults]; //[preferences persistentDomainForName:LocalPath]; [preferences setObject:UIImagePNGRepresentation(image) forKey:key];} //本地是否有相關圖片+ (BOOL)LocalHaveImage:(NSString*)key { NSUserDefaults* preferences = [NSUserDefaults standardUserDefaults]; //[preferences persistentDomainForName:LocalPath]; NSData* imageData = [preferences objectForKey:key]; if (imageData) { return YES; } return NO;} //從本地擷取圖片+ (UIImage*)GetImageFromLocal:(NSString*)key { NSUserDefaults* preferences = [NSUserDefaults standardUserDefaults]; //[preferences persistentDomainForName:LocalPath]; NSData* imageData = [preferences objectForKey:key]; UIImage* image; if (imageData) { image = [UIImage imageWithData:imageData]; } else { NSLog(@"未從本地獲得圖片"); } return image;}