第一种方式:官方提供的方法
异步获取图片,通过队列实现,而且图片会有缓存,在下次请求相同的连接的时候 系统会自动调用缓存 而不从网上请求数据
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 100.0f, 100.0f, 100.0f)];
[imageView setImageWithURL:[NSURL URLWithString:@"http://i./r4uwx.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]];
[self.view addSubview:imageView];
//placeholderImage后面跟的是网络图片返回之前设置显示的图片
第二种是常用的方法 就是使用三方SDWebImage
//导入头文件
#import <UIImageView+WebCache.h>
UIImageView *view = [[UIImageView alloc] initWithFrame:(self.view.bounds)];
view.backgroundColor = [UIColor purpleColor];
NSURL *url = [NSURL URLWithString:@"http://img5q.duitang.com/uploads/item/201505/15/20150515115147_JcfrZ.png"];
[view sd_setImageWithURL:url];
[self.view addSubview:view];