Xcode iPhone Programming: Loading a jpg into a UIImageView from URL

前端 未结 5 1783
忘了有多久
忘了有多久 2020-12-12 16:35

My app has to load an image from a http server and displaying it into an UIImageView
How can i do that??
I tried this:

NSString *temp = [NSStrin         


        
5条回答
  •  心在旅途
    2020-12-12 17:07

    This is the actual code.

    UIImageView *myview=[[UIImageView alloc]init];
    
        myview.frame = CGRectMake(0, 0, 320, 480);
    
        NSURL *imgURL=[[NSURL alloc]initWithString:@"http://soccerlens.com/files/2011/03/chelsea-1112-home.png"];
    
        NSData *imgdata=[[NSData alloc]initWithContentsOfURL:imgURL];
    
        UIImage *image=[[UIImage alloc]initWithData:imgdata];
    
        myview.image=image;
    
        [self.view addSubview:myview];
    

提交回复
热议问题