GDRSImageCache 1.0.1

GDRSImageCache 1.0.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最新发布2015年9月

Gabriel Radu 维护。



  • Gabriel Radu

GDRSImageCache 是为 iOS 设计的简约缓存和图像调整大小库。给定一个 URL,它在后台线程中检索图像并在内存中缓存它。GDRSImageCache 可以提供一个过滤块,用于在缓存之前调整从 URL 获取的图像的大小。

安装

手动安装

GDRSImageCache 目录拖动以下四个文件到 XCode 的项目导航器中

  • GDRSImageCache.h
  • GDRSImageCache.m
  • UIImage+GDRSResizing.h
  • UIImage+GDRSResizing.m

同时确保它们已添加到您的目标中。

使用方式

GDRSImageCache 的典型使用方式如下

UIImageView *anImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];

// create the cache
GDRSImageCache *cache = [[GDRSImageCache alloc] initWithCachedImageFilter:^UIImage *(UIImage *sourceImage) {

    // resize the image to the image view size and round the image corners; 
    // this is called by the cache on a background thread
    return [sourceImage gdrs_resizedImageToAspectFitSize:anImageView.bounds.size cornerRadius:10];

}];

// set the default image, which will be returned from
// fetchImageWithURL:completionHandler: if an image coresponding to the
// requested url is not cached yet.
cache.defaultImage = [UIImage imageNamed:<#place holder image name#>];


NSURL *imageUrl = <#an url to a image#>;

// fetch an image; the call returns imidiatly and the callback handler
// is called when the image is fetched over the network
anImageView.image = [cache fetchImageWithURL:imageUrl completionHandler:^(UIImage *image, NSError *error) {
    anImageView.image = image;
}];

要自己使用 GDRSImageCache 类,您需要 #import <GDRSImageCache/GDRSImageCache.h>。对于 UIImage 的调整大小方法(例如 gdrs_resizedImageToAspectFitSize:),您需要 #import <GDRSImageCache/UIImage+GDRSResizing.h>