egoimageview 使用2
来源:互联网 发布:澳洲机场退税软件 编辑:程序博客网 时间:2024/06/05 03:22
上次在《iOS学习笔记46——图片异步加载之SDWebImage》中介绍过一个开源的图片异步加载库,今天来介绍另外一个功能类似的EGOImageLoading,看名字知道,之前的一篇学习笔记《IOS学习笔记34—EGOTableViewPullRefresh实现下拉刷新》中介绍的开源项目是同一个作者。和SDWebImage不同,EGOImageLoading是实现了一个自定义的EGOImageView,使用上和UIImageView非常类似,同时也实现了自动缓存和缓存手动清理的功能。SDWebImage是在UIImageView中添加了一个类别,使用起来好像是使用自带的方法一样,而EGOImageView就完全是一个自定义实现的图片加载组件。这是Github的项目地址:https://github.com/enormego/EGOImageLoading
一、配置工程
到Github页面clone下项目后,里面有个Demo工程,可以自行运行下看看,然后将下载包中的EGOImageLoading拖拽到自己的工程中,并选中Copy····拷贝到项目后确定。这时可以Command+B编译一下,如果工程使用了ARC那么会报错,这时选中工程并选择Biuld Pases,为Compile Sources下的EGO开头的文件加上配置-fno-objc-arc(如图)
这时再Command+B就会看到编译通过了,这就说明项目集成成功了!
二、基本使用
使用起来也很简单,我们这个Demo来实现一个自定义Cell的UITableView列表并异步加载每个Cell的图片显示,单击每个Cell进入子页面并显示单独的图片。
首先我们需要实现一个继承UITableViewCell的自定义cell,头文件如下,声明一个EGOImageView用于显示图片,一个UILabel用于显示该图片的URL:
- #import <UIKit/UIKit.h>#import "EGOImageView.h"@interface ImageCell : UITableViewCell{@private EGOImageView *egoImageView; UILabel *label;}//在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 中调用为图片组件加载图片显示-(void)setImageWithURL:(NSString *)imageURL;@end
在.m文件中我们初始化这两个组件并实现setImageWithURL:方法:
- #import "ImageCell.h"@implementation ImageCell- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { egoImageView = [[EGOImageView alloc] initWithPlaceholderImage:[UIImage imageNamed:@"placeholder.png"]]; egoImageView.frame = CGRectMake(5, 5, 65, 65); [self.contentView addSubview:egoImageView]; label = [[UILabel alloc] initWithFrame:CGRectMake(78, 20, 220, 30)]; label.textColor = [UIColor blackColor]; [self.contentView addSubview:label]; } return self;}-(void)setImageWithURL:(NSString *)imageURL{ [egoImageView setImageURL:[NSURL URLWithString:imageURL]]; label.text = imageURL;}
其中EGOImageView初始化方法中的palaceholder是还没加载完或加载失败时显示的占位图。到这里自定义的UITableViewCell就实现完了,接着到UITableViewController中实现页面展示和功能(关键代码):
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"Cell"; ImageCell *cell = (ImageCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[ImageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } //imgURLs为存储图片URL地址的NSArray数组 [cell setImageWithURL:[imgURLs objectAtIndex:indexPath.row]]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell;}
我们可以看到,调用自定义的ImageCell中的setImageWithURL:方法即完成了对图片的异步加载,是不是很简单,另外,使用EGOCaceh也可以实现对缓存的释放:
- //清理缓存-(void)clearCacheButton{ [[EGOCache currentCache] clearCache]; [self.tableView reloadData];}
最后让我们来看看Demo的效果:
需要源码的同学可以到这里下载,里面有完整的实现:下载
- egoimageview 使用2
- EGOImageView 解析 使用
- (转)EGOImageView 解析 使用
- EGOImageView 使用方法
- EGOImageView与SDWebImage
- EGOImageView-缓存问题
- EGOImageView图片缓存加载
- EGOImageView的使用方法及注意事项
- 有关EGOImageView缓存的问题
- EGOImageView的使用方法及注意事项
- EGOImageView的使用方法及注意事项
- Low memory warning with several EGOImageView
- EGOImageView 滚动无法加在图片
- EGOImageView第三方库的应用
- 关于egoImageView类库的使用方法 和小技巧
- iPhone开发笔记(20)EGOImageView的使用方法及注意事项
- iOS 关于egoImageView类库的使用方法 和小技巧
- 关于egoImageView类库的使用方法 和小技巧
- 有关于数组的一些操作
- Relative相对布局的一些属性
- 数组排序
- 第九周项目二 时间类的输入输出符的重载
- linux下配置phpredis
- egoimageview 使用2
- oc 字符串操作
- Android游戏开发之数据库SQLite 详细介绍(十七)
- thinkphp route路由类解析 ——正则路由规则路由
- android的color值
- 九宫格---可滑动,可调整每行有几列,共有几行,边距可自适应
- jstl 获取Parameter参数 , switch使用
- Android学习能力之移动应用分析
- 在EditPlus里直接运行PHP