iOS實現(xiàn)圖片存在本地、再從本地獲取圖片的功能
更新時間:2017年03月23日 15:23:08 作者:鴻鵠當高遠
本文主要介紹了iOS實現(xiàn)圖片存在本地、再從本地獲取圖片的功能的代碼。具有很好的參考價值。下面跟著小編一起來看下吧
iOS實現(xiàn)圖片存在本地、再從本地獲取圖片的功能,代碼如下:
//將圖片保存到本地
+ (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;
}
以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
您可能感興趣的文章:
相關文章
詳解IOS11新特性之larget title的實現(xiàn)
本篇文章主要介紹了詳解IOS11新特性之larget title的實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-12-12

