Quote:
Originally Posted by opetopic
Why not do:
Code:
NSString *html = @"<html><body><img src='http://www.domain.com/path/to/your/image.jpg' width='100%' height='100%'></body></html>";
[webView loadHTMLString:html baseURL:nil];
|
Thanks for the suggestion! I had the same problem, could not solve it. With your hint I got it to work, after a minor modification:
Code:
// 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 experimental): 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];
If I set the image width property to 100%, it's too small - I don't understand why. When I do this AND turn off the UIWebView's scalesToFit property, then it works, but this means I cannot zoom in on the image (which I definitely want). So after a little experimenting I arbitrarily set the width to 900, and this works fine for what I want.
Thx!
Pieter