Search code examples
imagemobilefontsuiwebviewscale

Adjusting font size and image in UIWebView iOs


I am interested in displaying the following URL in a UIWebView: https://mlogin.yahoo.com/

The trouble is that this page renders too large on an iPad.

You can try opening the URL in Safari (on an iPad) directly and you will see what I mean.

I want to present the page in a UIWebView so that it looks aesthetically pleasing and not bloated and gigantic.

I tried the following approach (which does help partially)

- (void)webViewDidFinishLoad:(UIWebView *)wView {
    [wView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '50%'"];
}

However, this approach only changes the font size. The images still look fugly.

Anybody got any ideas?

Maybe inserting something like:

<meta name="viewport" content="width=320"/> 

in the head of the document would help?

If so, can anyone give the code snippet to insert this programmatically (in a similar fashion to changing text size code provided by me).


Solution

  • I eventually used the following which achieves my purpose:

    - (void)webViewDidFinishLoad:(UIWebView *)wView {
        [wView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '50%'"];
        [wView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.zoom= '0.5'"];
    }