网络获取图片
2017-10-25 本文已影响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];