通过URL获取图片

第一种方式:官方提供的方法
异步获取图片,通过队列实现,而且图片会有缓存,在下次请求相同的连接的时候 系统会自动调用缓存 而不从网上请求数据

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];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值