2014-06-23 43 views
0
__block UIActivityIndicatorView *activityIndicator; 
__weak UIImageView *weakImageView = self.headpic; 
[self.headpic setImageWithURL:imageUrl placeholderImage:nil options:SDWebImageProgressiveDownload progress:^(NSInteger receivedSize, NSInteger expectedSize){ 
if (!activityIndicator) { 
    [weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]]; 
    activityIndicator.center = weakImageView.center; 
    [activityIndicator startAnimating]; 
    } 
} 
        completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType){ 
         [activityIndicator removeFromSuperview]; 
         activityIndicator = nil; 
        }]; 

這個代碼可以設置headpic的形象,我想(從IMAGEURL)服務器映像下載到NSHomeDirectory在同一時間,怎麼辦?下載圖像到NSHomeDirectory使用SDWebImage

+0

所以你問如何保存'UIImage'到文件? – trojanfoe

+0

@trojanfoe感謝您的回覆,我想我明白了。 – yegomo

回答

0

查看EGOCache在本地存儲圖像。 https://github.com/enormego/EGOCache 您可以使用默認的EGOCache目錄(NSCachesDirectory內部)或使用您自己的目錄對其進行初始化。

用法很簡單:

[[EGOCache globalCache] setImage:image forKey:@"your_key"];