溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

iOS實現(xiàn)圖片存在本地、再從本地獲取圖片的功能

發(fā)布時間:2020-09-08 10:19:16 來源:腳本之家 閱讀:211 作者:鴻鵠當(dāng)高遠 欄目:移動開發(fā)

iOS實現(xiàn)圖片存在本地、再從本地獲取圖片的功能,代碼如下:

//將圖片保存到本地
+ (void)SaveImageToLocal:(UIImage*)image Keys:(NSString*)key {
 NSUserDefaults* preferences = [NSUserDefaults standardUserDefaults];
 //[preferences persistentDomainForName:LocalPath];
 [preferences setObject:UIImagePNGRepresentation(image) forKey:key];
}
 
//本地是否有相關(guān)圖片
+ (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;
}

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持億速云!

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI