zoukankan      html  css  js  c++  java
  • SDWebImage

    SDWebImage是一个可以自动管理图片加载的类库 --- 图片加载非常耗费流量 --- 在移动平台上要非常小心 --- 本地缓存

    》SDWenImage功能强大 --- 有一个UIImageView的category,用法简单

    - (void)setImageWithURL:(NSURL *)url 
    

     》SDWebImageManager,使用它可以进行一些异步加载的工作,参考文档:

    https://github.com/rs/SDWebImage#readme

    SDWebImage --- 简化网络图片出路

    1》导入UIImageView+WebCache,调用TableView的数据源代理方法- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;用sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder 异步加载图片

    #import "UIImageView+WebCache.h"
    
    ...
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *cell_id = @"myTableViewCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cell_id forIndexPath:indexPath];
    
        if (cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                           reuseIdentifier:MyIdentifier] autorelease];
        }
    // 给imageView异步加载图片
       [cell.imageView sd_setImageWithURL:[NSURL URLWithString:self.pictureStringArray[indexPath.row]] placeholderImage:[UIImage imageNamed:@"1.jpg"]];
    
    
        cell.textLabel.text = @"111;
        return cell;
    }
    

     2》SDWebImageManager

         The SDWebImageManager is the class behind the UIImageView+WebCache category. It ties theasynchronous downloader with the image cache store. You can use this classe directly to benefitsfrom web image downloading with caching in another context than a UIView

         下面是如何使用SDWebImageManager一个简单的例子

    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    
    UIImage *cachedImage = [manager imageWithURL:url];
    
    if (cachedImage)
    {
        // Use the cached image immediatly
    }
    else
    {
        // Start an async download
        [manager downloadWithURL:url delegate:self];
    }
    

      》遵守SDWebImageManagerDelegate协议,实现webImageManager:didFinishWithImage:

    - (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage *)image
    {
        // Do something with the downloaded image
    }
    
  • 相关阅读:
    每个人在公司都有自己的品牌--如何做一名优秀的管理者
    ios 逆向
    游戏整理
    Mac 开发装机必备
    php整理
    mongodb 学习
    python 学习
    pdf 下载整理
    C# 整理
    微服务学习
  • 原文地址:https://www.cnblogs.com/bachl/p/4692938.html
Copyright © 2011-2022 走看看