当前位置

网站首页> 程序设计 > 开源项目 > 编程语言 > 浏览文章

iOS 图片缓存库 GDRSImageCache

作者:小梦 来源: 网络 时间: 2024-06-26 阅读:

GDRSImageCache 是 iOS 一个非常小型的图片缓存和更改图片大小的开发包。给定一个 URL 后该库会通过后台线程获取图片并在内存中缓存。

使用方法:

UIImageView *anImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];// create the cacheGDRSImageCache *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 networkanImageView.image = [cache fetchImageWithURL:imageUrl completionHandler:^(UIImage *image, NSError *error) {    anImageView.image = image;}];

热点阅读

网友最爱