It turns out it is trivial to load images into iPhone native applications.
This simple function will do all of the work. No UIWebView required no NSURLConnection required. Just dataWithContentsOfURL.
-(UIImage*) newUIImageWithURLString:(NSString*)urlString
{
return [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]]];
}
Usage:
UIImage* myUIImage = [self newUIImageWithURLString:@"http://example.com/images/myimage.jpg"];
That's it!
It is important to note that +(NSData*) dataWithContentsOfURL:(NSURL*)url blocks. This will not do an asynchronous load. :( I am looking into another more involved solution that will load images on a separate thread.
Saturday, August 23, 2008
Subscribe to:
Post Comments (Atom)
2 comments:
Have you fount a way to make asynchronous loads of images?
hi can you give me a smaple code or a tutorial on how to do this my email is adamwweraw@hotmail.com
Post a Comment