I’m working on an app that can retrieve images from the web. Rather than actually download the images, I’m trying to display them in a UIWebView. I really need the images to be a specific size on my screen, so I have made a webview of the size I need, and told it to scalesPageToFit, but when I run, the image is not the correct size within the view. I am using a 1024×768 image as a test, and have tried numerous iterations of view sizes to get it correct on my screen, but I either end up with an illogical size, or it clips.
Here is the original image; http://www.coolopticalillusions.com/backgrounds/freaky-desktop-background-7.jpg
I am trying to make the image 300 wide, which preserving aspect ratio, would mean the view should be 245 high.
This first screenshot is with a 300×245 UIWebView, you can see the width is correct, but the height is not, the red box should be aligned exactly with the bottom of the image
http://img839.imageshack.us/f/sizecropped.png/
This second screenshot is with a 300×300, which scales the image too wide for the view, and also too high as well.
http://img155.imageshack.us/f/sizetoobig.png/
I have been struggling for a while trying to get this to do what I want it to, but I am just not having any success whatsoever.
EDIT: The only relevant code I have is this:
NSMutableString *urlString = [[NSMutableString alloc] initWithString:@"http://www.coolopticalillusions.com/backgrounds/freaky-desktop-background-7.jpg"];
NSURL* url = [[NSURL alloc] initWithString:urlString];
NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:url];
[messageView.imageWebView loadRequest:urlRequest];
messageView.imageWebView.scalesPageToFit = YES;
I would create the webview first with the application frame as frame. Then you can add your image to a new imageview which has your size (300×245). Add the image to the webview as subview.
Let me know if that helped.