iOS_第3方类库SDWebImage简单使用

iOS_第3方类库SDWebImage简单使用,有需要的朋友可以参考下。


1,将下载好的第3方类库SDWebImage源码包加入到工程

2,进入工程的Build Phases,将源码包里面的所有.m文件全部添加到工程

3,导入第3方类库依赖的两个系统自带的框架:MapKit.framework、ImageIO.framework

4,添加第3方类库的主头文件"UIImageView+WebCache.h"



代码使用片段:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *cellID = @"Beyond";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        // 如果池中没取到,则重新生成一个cell
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
    }
    // 设置cell中独一无二的内容
    Status *s = _statuses[indexPath.row];
    cell.textLabel.text = s.text;
    cell.detailTextLabel.text = s.user.screenName;
    cell.textLabel.numberOfLines = 0;
    // 重要~使用第3方框架 SDWebImage,缓存策略:失败再请求,磁盘缓存,scrollView滚动时暂停下载图片
    [cell.imageView setImageWithURL:[NSURL URLWithString:s.user.profileImageUrl] placeholderImage:[UIImage imageNamed:@"avatar_default.png"] options:SDWebImageLowPriority | SDWebImageRefreshCached | SDWebImageRetryFailed];
    // 返回cell
    return cell;
}

关键代码,缓存策略:

失败再请求:SDWebImageRetryFailed

磁盘缓存:SDWebImageRefreshCached

scrollView滚动时暂停下载图片:SDWebImageLowPriority


[cell.imageViewsetImageWithURL:[NSURLURLWithString:s.user.profileImageUrl]placeholderImage:[UIImageimageNamed:@"avatar_default.png"]options:SDWebImageLowPriority|SDWebImageRefreshCached |SDWebImageRetryFailed];

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值