开发者

How to load image from remote server on the UIImageView in iphone?

开发者 https://www.devze.com 2022-12-14 13:20 出处:网络
I am trying to load image from a remote server on the UIImageView in my application. Is it possible to load image from a remote server. I am using the following code

I am trying to load image from a remote server on the UIImageView in my application. Is it possible to load image from a remote server. I am using the following code

id path = @"http开发者_JAVA技巧://upload.wikimedia.org/wikipedia/commons/c/c7/Sholay-Main_Male_Cast.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];

I found this code sippnet on the net, but I dont understand how do I load this image on the ImageView.

Can anyone tell me how to add image on the UIImageView.

Thanx in advance...


you got almost all the way there... now just

imageView.image = img;

note that using dataWithContentsOfURL will block your user interface while the image loads, which will work if you're loading small images at startup, but is generally a bad idea; look into NSURLConnection.

0

精彩评论

暂无评论...
验证码 换一张
取 消