iPhone – Auto resizing UIWebView content do not fit the frame

Spread the love

Question Description

I’m generating an UIWebView into my viewDidLoad method, with a tiny size (let’s say something like 50×70). And then I put it into a super UIView.

I’d like to make its content fit the webView frame. To do this, I wrote :

        oneView = [[UIWebView alloc] initWithFrame:CGRectMake(x, y, W, H)];
        oneView.backgroundColor = [UIColor whiteColor];
        oneView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        oneView.scalesPageToFit = YES;
        oneView.autoresizesSubviews = YES;

        [self.view addSubview:oneView];
        [oneView loadRequest:/*some request*/];

But doing this, the web page is not resized to the frame of the UIWebView.
It seems to be scaled to something else, smaller than the superview’s frame, and wider than the webview’s one.

enter image description here

If I set the webview frame size to the whole superview’s size, it’s ok.
How may I force the web content (real www content) to fit the frame of the “reduced” UIWebView ?

Practice As Follows

The answer is: you are already doing this but there are limits.

Look at the following screenshots:

Screeshot 1, scalesPageToFit YES and NO

Both webview have the same width. In the lower one the page fits perfectly.

enter image description here

Screeshot 2, scalesPageToFit both YES but smaller widths set

Both webview try to fit the page but it won’t as there is a size limit.

enter image description here

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.