异步加载及缓存远程图片的iOS类库:SDWebImage

lpkde 10年前

这个类库提供一个UIImageView类别以支持加载来自网络的远程图片。具有缓存管理、异步下载、同一个URL下载次数控制和优化等特性。

#import <SDWebImage/UIImageView+WebCache.h>    ...    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  {      static NSString *MyIdentifier = @"MyIdentifier";        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];        if (cell == nil)      {          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault                                         reuseIdentifier:MyIdentifier] autorelease];      }        // Here we use the new provided setImageWithURL: method to load the web image      [cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]                     placeholderImage:[UIImage imageNamed:@"placeholder.png"]];        cell.textLabel.text = @"My Text";      return cell;  }

它提供了:

  • An UIImageView category adding web image and cache management to the Cocoa Touch framework
  • An asynchronous image downloader
  • An asynchronous memory + disk image caching with automatic cache expiration handling
  • Animated GIF support
  • WebP format support
  • A background image decompression
  • A guarantee that the same URL won't be downloaded several times
  • A guarantee that bogus URLs won't be retried again and again
  • A guarantee that main thread will never be blocked
  • Performances!
  • Use GCD and ARC
  • Arm64 support

项目主页:http://www.open-open.com/lib/view/home/1421592829125