SDWebImage使用入门
2015-07-17 06:47
483 查看
为什么要用它
(原文地址:http://blog.csdn.net/niu_gao)SDWebImage是一个从网站下载图片的库,它扩展了UIImageView类。UIImageView本来就可以直接从网站下载图片,但是它没有考虑对图片进行缓存,导致只要显示图片就要访问网络。而SDWebImage就解决了这个问题(当然不止这一个功能)。
下载位置
https://github.com/rs/SDWebImage编译
下载后直接打开工程进行编译即可。被其它工程使用
要在其它工程中使用有多种方式,最简单的就是把类,工程的引用添加到其它工程中。步骤如下:
l 在其它工程中,工程名字上点出弹出菜单。
l 选择Add files to “XXX”。
l 选择SDWebImage的工程文件,选中Copy items if needed。
l 点Add。
编译,通不过。因为缺少了一个库的源码,这个库叫libwebp。位置:https://github.com/webmproject/libwebp。
请下载0.4.3版,否则编译通不过。我说的是现在,过上几个月可以就需更高版本了。
把libwebp的src目录复制到SDWebImage中的Vendors/libwebp下。再编译,通过。
但是,运你的工程会崩溃(前提是你的工程中使用了SDWebImage的功能)。还需要添加链接选项:-ObjC。
如果此时运行依然出错,则还需要在“BuildPhases”中添加对ImageIO.framework的引用。
代码示例:#import<SDWebImage/UIImageView+WebCache.h> ... - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { staticNSString *MyIdentifier= @"MyIdentifier"; UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease]; } // 我们使用sd_setImageWithURL: 来加载web图像 [cell.imageViewsd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; cell.textLabel.text= @"My Text"; return cell; }
(原文地址:http://blog.csdn.net/niu_gao)
使用block//我们使用sd_setImageWithURL: 来加载web图像
[cell.imageView sd_setImageWithURL:
[NSURLURLWithString:@"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
... completion code here ...
}
];
相关文章推荐
- iOS开发实战:SDWebImage深度解析
- SDWebImage使用——一个可管理远程图片加载的类库
- sdwebImage 如何清除缓存
- iOS多线程编程及简单封装图片下载
- Xcode6编译SDWebImage报错解决方法(SDWebImageDownloaderOperation.m错误)
- SDWebImage
- SDWebImage源码解析之SDWebImageManager的注解
- iOS网络编程(三) 异步加载及缓存图片---->SDWebImage
- SDWebImage手动清除缓存的方法
- SDWebImage缓存
- SDWebImage关于地址https 带有 ssl证书的图片加载
- 用SDWebImage开源库异步下载图片
- sdwebimage缓存图片对比问题
- 第三方框架SDWebImage的使用
- SDWebImage类实现图片的下载
- iOS_第3方类库SDWebImage
- IOS网络图片缓存详解
- SDWebImage使用入门
- SDWebImage 内部运行机制浅析
- SDWebimage清空缓存