I built an iPhone application that loads *.png files (located in Resources) in a UIWebView. The reason to do so, is that I can easily have the user resize the image by multitouch (pinching).
The original image is larger than the UIWebView size, but it is automatically resized to fit. The problem is that it is now too small, it does not fill the screen. So I tried the UIView's autoresizingMask property:
and the UIWebView's scalesPagesToFit property:
it = YES;
None of them provide the result. Funny is that just an easy double tap on the screen is enough, so apparently the app does know how to handle the image if the user makes the request.
How can I have the app make this request at run time when loading the image, so the user sees an image that is fitted to the width of the screen.
ZIP file with code can be downloaded from:
Looking forward to your suggestions,
Pieter Kubben, MD
// Create url string for image file
NSString *imageName = [[NSBundle mainBundle] pathForResource:@"test_image" ofType:@"png"];
// Load image in UIWebView
NSURL *url = [NSURL fileURLWithPath: imageName];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL: url];
// Try automatic resize (to screen width)
// -- DOES NOT WORK --
imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
imageWebView.scalesPageToFit = YES;
// Perform request
[imageWebView loadRequest: urlRequest];