【问题标题】:downloading image into NSHomeDirectory by using SDWebImage使用 SDWebImage 将图像下载到 NSHomeDirectory
【发布时间】:2014-06-23 12:53:54
【问题描述】:
__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,怎么办?

【问题讨论】:

  • 那么您是在问如何将UIImage 保存到文件中?
  • @trojanfoe 感谢您的回复,我想我明白了。

标签: ios objective-c sdwebimage


【解决方案1】:

查看 EGOCache 以在本地存储图像。 https://github.com/enormego/EGOCache 您可以使用默认的 EGOCache 目录(在 NSCachesDirectory 中)或使用您自己的目录对其进行初始化。

用法很简单:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-10
    • 2020-04-15
    相关资源
    最近更新 更多