Resizing a UIWebView Frame Does Not Resize Internal Content

If I change the UIWebView frame (scalesPageToFit property - YES), what do I need to do so that the zoom level of the currently displayed web page is saved?

Let's say I have a UIWebView frame 200 pixels wide and enlarged to a website so that only one column can be seen. After changing the width to 300, I still see a column with the same size and extra space left and right. But what I need is that I still only see this column, but more.

Any ideas what I should do to achieve this? I tried a lot, but so far nothing has worked.

By the way, the iPhone created in the Safari browser does exactly this thing (with the same site, therefore it is not connected with the content) when the iPhone is rotated ... I see the same content, the error is bigger and not more content, since it happens with my current version of the code.

Thanks for the help! Marcus

+6
objective-c iphone uikit
source share
2 answers

EDIT : best answer:

mjdth correctly, you can use the contentMode property on a UIWebView . Very simple:

 webView.contentMode = UIViewContentModeRedraw; 

Old crappy answer:

This worked for me, but I worked with local pages and some content:

 -(void)layoutSubviews { // Cause web view to reload content in order to display at new frame size [webView reload]; } 

I would like to see a better solution that does not require a page reload!

+1
source share

What did you set for webview UIViewContentMode (can also be set in IB in the "Mode" section)? Since you are resizing the view, this may have something to do with it. Just a shot in the dark since I haven't tried it, but hopefully this helps.

You can also try disabling scalesPageToFit before switching and turning it back on.

0
source share

All Articles