网络获取图片

{

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];

你可能感兴趣的:(网络获取图片)