zoukankan      html  css  js  c++  java
  • SDWebImage

    https://github.com/rs/SDWebImage

    使用示范的代码:

    UITableView使用UIImageView+WebCache类(基本应用,UIImageView的一个category)

     

    复制代码
     1 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    2 static NSString *MyIdentifier = @"MyIdentifier";
    3 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    4 if (cell == nil) {
    5 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
    6 }
    7 // Here we use the new provided setImageWithURL: method to load the web image
    8 [cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    9 cell.textLabel.text = @"My Text";
    10 return cell;
    11 }
    复制代码
    基本代码:[imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/image.jpg"]];

    使用SDWebImageManager类:可以进行一些异步加载的工作。

    复制代码
    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    UIImage *cachedImage = [manager imageWithURL:url]; // 将需要缓存的图片加载进来
    if (cachedImage) {
    // 如果Cache命中,则直接利用缓存的图片进行有关操作
    // Use the cached image immediatly
    } else {
    // 如果Cache没有命中,则去下载指定网络位置的图片,并且给出一个委托方法
    // Start an async download
    [manager downloadWithURL:url delegate:self];
    }
    复制代码
    webImageManager:didFinishWithImage:方法。
    // 当下载完成后,调用回调方法,使下载的图片显示
    - (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage *)image {
    // Do something with the downloaded image
    }
    独立的异步图像下载
    可能会单独用到异步图片下载,则一定要用downloaderWithURL:delegate:来建立一个SDWebImageDownloader实例。
    downloader = [SDWebImageDownloader downloaderWithURL:url delegate:self];

    独立的异步图像缓存
    SDImageCache类提供一个创建空缓存的实例,并用方法imageForKey:来寻找当前缓存。
    UIImage *myCachedImage = [[SDImageCache sharedImageCache] imageFromKey:myCacheKey];

    存储一个图像到缓存是使用方法storeImage: forKey:
    [[SDImageCache sharedImageCache] storeImage:myImage forKey:myCacheKey];
    来替代。
  • 相关阅读:
    超级管理员登录后如果连续XX分钟没有操作再次操作需要重新登录
    linux下连接本地的navicate
    linux 日常中会用到的命令(持续更新)
    关于PHP的 PHP-FPM进程CPU 100%的一些原因分析和解决方案
    VMware Workstation 14 激活码
    破解phpstorm
    redis五种数据类型的使用场景
    关于Nginx负载均衡的6种策略
    PHP和PHP-FPM 配置文件优化
    redis配置文件详解
  • 原文地址:https://www.cnblogs.com/lidongq/p/4202693.html
Copyright © 2011-2022 走看看