5

I've come across an interesting problem with UIWebView.

I basically want to use a UiWebView on an iPad app as a modal pop-up to show wikipedia or amazon mobile pages if the user performs certain actions.

I have the code to create and load the UIWebView working fine, but the content loaded pays no attention to the width of the UIWebView. I wanted the UIWebView to (roughly) be the width of an iPhone screen and have set the frame accordingly.

However, when the content loads it appears that it loads at the width and height of an iPad screen so it scrolls both horizontally and vertically. Vertical scrolling is fine but horizontal is not.

When the same URLs are loaded on the iPhone (just in safari), the content resizes to fit the width of the device, which I assume is using a meta-tag?

The question is, how I can replicate this behaviour in a UIWebView on the iPad and "force" the content down to a set width.

Update

Apologies, this is a duplicate of the question answered at UIWebView -- load external website, programmatically set initial zoom scale, and allow user to zoom afterwards

This solution is smart and works.

Community
  • 1
  • 1
AustinRathe
  • 671
  • 1
  • 10
  • 21
  • possible duplicate of [UIWebView -- load external website, programmatically set initial zoom scale, and allow user to zoom afterwards](http://stackoverflow.com/questions/8044769/uiwebview-load-external-website-programmatically-set-initial-zoom-scale-and) – greg Sep 02 '14 at 11:55

1 Answers1

0

The size of the content will depend on a mix of the size of the browser's viewport, as well as the HTML / CSS that is implemented on the site.

As you are saying the site scales correctly in Safari, Check the frame of the webView is correct in your app. Sometimes the site may have implemented aspect ratio comparisons to work out which responsive view to show, so experiment also with the height of the modal to match the size of an iPhone.

Another thing you can try is setting constraints on the webView. I've found setting constraints will also sometimes alter the viewport size & rendering.

If that doesn't work - You could also try scaling the content. The answer here will help: HTML Content fit in UIWebview without zooming out

Community
  • 1
  • 1
Steve Forbes
  • 230
  • 1
  • 6