你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS下載網絡圖片

iOS下載網絡圖片

編輯:IOS開發綜合
-(void)setWebImage:(NSURL *)aUrl placeHolder:(UIImage *)placeHolder downloadFlag:(int)flag{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
//配置下載路徑
NSString *path=[NSHomeDirectory() stringByAppendingFormat:@"/Library/Caches/%lu",(unsigned long)aUrl.description.hash];
NSData *data=[NSData dataWithContentsOfFile:path];
if (!data) {
NSLog(@"准備下載到沙盒路徑:%@",path);
data=[NSData dataWithContentsOfURL:aUrl];
[data writeToFile:path atomically:YES];
}
UIImage *image=[UIImage imageWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
if (self.tag==flag) {
[self setImage:image];
}
});
});
}
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved