So, the problem that I am currently facing is displaying UIWebViews with a single image. I would like the image to be scaled down if it doesn't fit the place, and keep it in its original size if not. So, here is how I do it (in a UIViewController):
- (void)viewDidLoad { [super viewDidLoad]; UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 80)]; NSString *path =[[NSBundle mainBundle] bundlePath]; NSURL *baseUrl =[NSURL fileURLWithPath:path]; NSString *html = [NSString stringWithFormat:@"<html><head>" //THE LINE ABOVE IS TO PREVENT THE VIEW TO BE SCROLLABLE "<script>document.ontouchstart = function(event) { event.preventDefault(); }</script>" "</head><body style=\"text-align:center;margin:0;padding:0\">" "<img src=\"banner.gif\" />" "</body>" "</html>"]; webView.scalesPageToFit = YES; [webView loadHTMLString:html baseURL:baseUrl]; [self.view addSubview:webView]; [webView release]; }
This crop the image and makes scrollable web browsing, which is not the desired behavior.
So, I started using the CSS image tag:
"<img style=\"width:100%\" src=\"banner.gif\" />"
or
"<img style=\"max-width:100%\" src=\"banner.gif\" />"
I donโt know why, but 100% does not seem to be the width of the UIView, it is really small! (the original image in the view is more than 320 pixels, and here is the result :)

So, I tried to set the width of the body:
"</head><body style=\"width:100%;text-align:center;margin:0;padding:0\">" "<img style=\"width:100%\" src=\"banner.gif\" />"
And what that means is simply interfering with the text-align property. I also tried to remove the text alignment, because if the width matches the view, it is not needed, but it still does not work. I also tried to set the image size to the width of the view, but it does not work on retina devices, then ... I tried to set the viewport to the width of the device, but it does not change.
Any idea on how to do this?
Here is a small sample with 3 images that I would like to place if you have time to look