IOS学习之路二十三(EGOImageLoading异步加载图片开源框架使用)

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














  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值