美文网首页
网络获取图片

网络获取图片

作者: 法库德 | 来源:发表于2017-10-25 14:12 被阅读0次

{

UIImageView *vi;

}

[super viewDidLoad];

self.view.backgroundColor=[UIColor whiteColor];

vi=[[UIImageView alloc]initWithFrame:CGRectMake(40, 120, 300, 200)];

[self.view addSubview:vi];

NSString *str=[NSString stringWithFormat:@"http://pic1.zhimg.com/v2-7f69a4fc4a0aa84178074d83aef7ac30_r.jpg"];

NSURL *url=[NSURL URLWithString:str];

NSURLRequest *req=[[NSURLRequest alloc]initWithURL:url];

NSURLResponse *resq=[[NSURLResponse alloc]init];

NSData *da=[NSURLConnection sendSynchronousRequest:req returningResponse:&resq error:nil];

vi.image=[UIImage imageWithData:da];

相关文章

网友评论

      本文标题:网络获取图片

      本文链接:https://www.haomeiwen.com/subject/goeqpxtx.html