EGOImageLoading 是一个用的比较多的异步加载图片的第三方类库,简化开发过程,我们直接传入图片的url,这个类库就会自动帮我们异步加载和缓存工作;当从网上获取图片时,如果网速慢图片短时间内不能下载下来,可以先用一张本地的图片代替显示,还可以进行其他操作,让图片下载完成后自动替换占位图片而不影响用户体验;

原文转自:http://blog.csdn.net/wildcatlele/article/details/11536939

EGOImageLoading 的GitHub 下载地址:  https://github.com/enormego/EGOImageLoading

GitHub上下载下来的类库会有一个Demo,如果运行出错说明缺少EGOCache类,在https://github.com/enormego/EGOCache添加道工程之中,或者直接点击这里下载

配置很简单:

下载源代码解压缩后直接拖到项目目录中;

添加ImageIO.framwork;

下面附上我自己写的一个自定义UitableViewCell代码:

结果代码展示:

EGOImageLoading写的自定义代码如下:

OneImageTableViewCell.h

//
// OneImageTableViewCell.h
// ImageViewRefreshDemo
//
// Created by WildCat on 13-9-7.
// Copyright (c) 2013年 wildcat. All rights reserved.
// #import <UIKit/UIKit.h>
@class EGOImageView; //声明头
@interface OneImageTableViewCell : UITableViewCell
@property (nonatomic) EGOImageView *egoImageView;//ImageView类型为:EGOImageView
@property (nonatomic,retain) UILabel *titleLabel;
@property (nonatomic,retain) UILabel *addressLabel;
@property (nonatomic,retain) UILabel *dateLabel;
-(void) setUrlByString:(NSString *) urlStr;
@end

OneImageTableViewCell.m

//
// OneImageTableViewCell.m
// ImageViewRefreshDemo
//
// Created by WildCat on 13-9-7.
// Copyright (c) 2013年 wildcat. All rights reserved.
// #import "OneImageTableViewCell.h"
#import "EgoImageView.h"
@implementation OneImageTableViewCell
@synthesize titleLabel;
@synthesize addressLabel;
@synthesize dateLabel;
@synthesize egoImageView;
-(void)setUrlByString:(NSString *)urlStr{
egoImageView.imageURL = [NSURL URLWithString:urlStr];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
egoImageView=[[EGOImageView alloc] initWithPlaceholderImage:[UIImage imageNamed:@"2.jpeg"]];//声明对象
egoImageView.frame=CGRectMake(227.0f, 9.0f, 66.f, 50.f);
[self.contentView addSubview:egoImageView]; addressLabel=[[UILabel alloc] initWithFrame:CGRectMake(13.0f, 58.0f, 42.f, 18.f)];
addressLabel.font=[UIFont systemFontOfSize:10.f]; titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(13.0f, .0f, 210.f, 59.f)];
titleLabel.lineBreakMode = UILineBreakModeWordWrap;
titleLabel.numberOfLines = 0;
titleLabel.font=[UIFont boldSystemFontOfSize:14.f];
dateLabel=[[UILabel alloc] initWithFrame:CGRectMake(240.0f, 59.0f, 52.f, 16.f)];
dateLabel.font=[UIFont systemFontOfSize:8.f]; [self.contentView addSubview:titleLabel];
[self.contentView addSubview:addressLabel];
[self.contentView addSubview:dateLabel]; }
return self;
} - (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated]; // Configure the view for the selected state
} @end

使用:

if (oneImageCell==nil) {
oneImageCell=[[OneImageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellWithOneImageIdentifier];
}
oneImageCell.backgroundView =sectionBagView;
oneImageCell.backgroundView.backgroundColor=[UIColor whiteColor];
oneImageCell.selectedBackgroundView = [[UIView alloc] initWithFrame:oneImageCell.frame] ;
oneImageCell.selectedBackgroundView.backgroundColor = [UIColor grayColor]; oneImageCell.titleLabel.text=nowTitle;
oneImageCell.addressLabel.text=address;
oneImageCell.dateLabel.text=date;
[oneImageCell setUrlByString:[imageUrlsArray objectAtIndex:1]];
return oneImageCell;

转载请注明:

新浪微博:http://weibo.com/u/3202802157

IOS学习之路二十三(EGOImageLoading异步加载图片开源框架使用)的更多相关文章

  1. Android学习笔记(二)之异步加载图片

    最近在android开发中碰到比较棘手的问题,就是加载图片内存溢出.我开发的是一个新闻应用,应用中用到大量的图片,一个界面中可能会有上百张图片.开发android应用的朋友可能或多或少碰到加载图片内存 ...

  2. swift 异步加载图片(第三方框架ImageLoader)

    import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: ...

  3. IOS开发之路二十一(UIWebView加载本地html)

    挺简单不多说的直接代码: // // ViewController.h // JSAndJson // // Created by WildCat on 13-9-8. // Copyright (c ...

  4. Android中ListView异步加载图片错位、重复、闪烁问题分析及解决方案

    我们在使用ListView异步加载图片的时候,在快速滑动或者网络不好的情况下,会出现图片错位.重复.闪烁等问题,其实这些问题总结起来就是一个问题,我们需要对这些问题进行ListView的优化. 比如L ...

  5. ios UITableView 异步加载图片并防止错位

    UITableView 重用 UITableViewCell 并异步加载图片时会出现图片错乱的情况 对错位原因不明白的同学请参考我的另外一篇随笔:http://www.cnblogs.com/lesl ...

  6. IOS中UITableView异步加载图片的实现

    本文转载至 http://blog.csdn.net/enuola/article/details/8639404  最近做一个项目,需要用到UITableView异步加载图片的例子,看到网上有一个E ...

  7. Android 异步加载图片,使用LruCache和SD卡或手机缓存,效果非常的流畅

      Android 高手进阶(21)  版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请注明出处http://blog.csdn.net/xiaanming/article/details ...

  8. 多线程异步加载图片async_pictures

    异步加载图片 目标:在表格中异步加载网络图片 目的: 模拟 SDWebImage 基本功能实现 理解 SDWebImage 的底层实现机制 SDWebImage 是非常著名的网络图片处理框架,目前国内 ...

  9. [置顶] 异步加载图片,使用LruCache和SD卡或手机缓存,效果非常的流畅

    转载请注明出处http://blog.csdn.net/xiaanming/article/details/9825113 异步加载图片的例子,网上也比较多,大部分用了HashMap<Strin ...

随机推荐

  1. Linux查看非root流程执行

    Linux查看非root流程执行 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ ps -U root -u root -N PID TTY TIME CMD ...

  2. 高性能网络server--I/O复 select poll epoll_wait之间的差

    一个.select 方式作为收集,最多只能监控1024描述叙事断裂的文件,内部使用位操作,相应的位置1或设置0,必须是可读.可写.三类除单独的事件,内部查询方法.将全部的套接字从内核到用户空间之间进行 ...

  3. Redis 安装与简单示例

    Redis 安装与简单示例 一.Redis的安装 Redis下载地址如下:https://github.com/dmajkic/redis/downloads 解压后根据自己机器的实际情况选择32位或 ...

  4. IOS中 init和initialize

    一.init和initialize 1.方法类型 1> init属于对象方法,-开头 2> initialize属于类方法,+开头 2.调用时刻 1> init:每个对象初始化的时候 ...

  5. Unofficial Microsoft SQL Server Driver for PHP (sqlsrv)非官方的PHP SQL Server 驱动

    原文 Unofficial Microsoft SQL Server Driver for PHP (sqlsrv) Here are unofficial modified builds of Mi ...

  6. Linux下给mysql创建用户分配权限

    1.新建用户 //登录MYSQL @>mysql -u root -p @>密码 //创建用户 mysql> insert into mysql.user(Host,User,Pas ...

  7. Excel基于POI导入导出的Annotation化之路(一)

    Excel在web项目里的使用变得越来越广泛,特别是和线下耦合度较高的业务,Excel导入导出变得非常频繁,尽管很多人写了诸多的工具方法,但是终究没有解决一个问题:有效的控制字段英文名称和实际表头名称 ...

  8. OpenSUSE 13.2使用VPN(PPTP)

    新年开始,有时查询个资料或是下个软件包并不是那么愉快,决定使用付费VPN,他们使用的是用户名及密码的验证方式 在网上找到了一个教程,挺详尽的,如果想按照步骤能使用即可的原则,跟着我一起设置,想了解更多 ...

  9. 【转】Android官方下拉刷新控件 SwipeRefreshLayout

    今天在Google+上看到了SwipeRefreshLayout这个名词,遂搜索了下,发现竟然是刚刚google更新sdk新增加的一个widget,于是赶紧抢先体验学习下. SwipeRefreshL ...

  10. AngularJs ng-repeat 必须注意的性能问题

    AngularJs 的 ng-repeat 让我们非常方便的遍历数组生成 Dom 元素,但是使用不当也会有性能问题. 在项目中我们使用 ng-repeat 加载完一个列表后,如果再次请求数据,然后过滤 ...