Search code examples
ios4uiimageview

How to get Image from a URL


Kindly tell me how can i get UIImage from a URL if i have URL from a JSon Get. I have been searching and found some tips but not succeeded yet. Kindly help me.

Thanks in advance.


Solution

  • Very simple in my point of view. Just use the following line of codes:

    NSURL *url = [NSURL URLWithString:@"http://yoursite.com/imageName.png/jpg"];

    NSData *myData = [NSData dataWithContentsOfURL:url];

    UIImage *image = [[[UIImage alloc] initWithData:myData] autorelease];

    Now use this image wherever you want. Hope this helps.

    Happy Coding!