Skip to content

Instantly share code, notes, and snippets.

@ikarius
Created April 9, 2010 13:47
Show Gist options
  • Save ikarius/361171 to your computer and use it in GitHub Desktop.
Save ikarius/361171 to your computer and use it in GitHub Desktop.
/*
** Display image in UIWebView using loadHTMLString
*/
- (void) showImageWithLoadHTMLString {
// Create URL string for image file location
NSString *imageName = [[NSBundle mainBundle] pathForResource:@"test_image" ofType:@"png"];
NSURL *imageURL = [NSURL fileURLWithPath: imageName];
// Create HTML string from image URL
// Width-value is arbitrary (and found experimentally): 900 works fine for me
NSString *htmlString = @"<html><body><img src='%@' width='900'></body></html>";
NSString *imageHTML = [[NSString alloc] initWithFormat:htmlString, imageURL];
// Load image in UIWebView
imageWebView.scalesPageToFit = YES;
[imageWebView loadHTMLString:imageHTML baseURL:nil];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment