如何在ios中使用UIImageView + AFNetworking异步加载图像

Dee*_*ary 2 objective-c uiimage ios afnetworking

我用这个:

UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:@"http://oldmaker.com/glamberry_v2/ios_Loading-Spinners.gif"]]];
Run Code Online (Sandbox Code Playgroud)

但这花费了太多时间.我想用来AFNetworking加快加载速度.

任何帮助,将不胜感激.

小智 9

您可以使用SDWebImage

它支持异步下载和缓存.

用法

只需#import UIImageView+WebCache.h标题

  [imgView sd_setImageWithURL:Url_Of_The_Image placeholderImage:[UIImage imageNamed:@"Sampleimage.png"]];
Run Code Online (Sandbox Code Playgroud)