SDWebImage施用
发布时间: 2013-10-08 16:32:36 作者: rapoo
SDWebImage使用
Web image(网络图像)
该库提供了一个支持来自Web的远程图像的UIImageView类别
它提供了:
添加网络图像和缓存管理到Cocoa Touch framework的UIImageView类别异步图像下载An asynchronous memory + disk image caching with automatic cache expiration handling支持GIF动画支持WebP格式后台图像解压保证相同的url不会下载多次保证伪造的URL不会尝试一遍又一遍的下载保证主线程永远不会被阻塞Performances!使用GCD和ARC注意:SDWebImage 3.0不向后兼容2.0并且最低需要iOS 5.0 的版本。如果你的iOS版本低于5.0,请使用2.0版本。
如何使用
API 文档地址 http://hackemist.com/SDWebImage/doc/。
Using UIImageView+WebCache category with UITableView 仅需引入 UIImageView+WebCache.h 头文件,在UITableViewDataSource的方法tableView:cellForRowAtIndexPath:中调用setImageWithURL:placeholderImage:方法。从异步下载到缓存管理,一切都会为你处理。
#import <SDWebImage/UIImageView+WebCache.h>- *:*:*static *= @"MyIdentifier"*= :if == nil= :// Here we use the new provided setImageWithURL: method to load the web image ::@"http://www.domain.com/path/to/image.jpg":@"placeholder.png"= @"My Text"return // Here we use the new provided setImageWithURL: method to load the web image::@"http://www.domain.com/path/to/image.jpg":@"placeholder.png"^***= :0 ^long long // progression tracking code ^**if // do something with image :0 ^long long // progression tracking code ^***BOOL if && // do something with image *= :@"myNamespace"::^*// image is not nil if image was found::- BOOLapplication:*application didFinishLaunchingWithOptions:*launchOptions:^*= :::return // Your app init code... return YES::@"https://graph.facebook.com/olivier.poitrey/picture":@"avatar-placeholder.png"
Import headers in your source files(导入头文件到你的资源文件中) 在你需要用到这个库的资源文件中导入下面的头文件:#import <SDWebImage/UIImageView+WebCache.h>
Build Project(编译工程) 这里你的工程应该是没有错误的。如果有,去google上找吧。
Future Enhancements(未来增强功能) LRU memory cache cleanup instead of reset on memory warning
Future Enhancements