UIWebView in UIPopover - Report size

ios, uipopovercontroller, uiwebview

Solution

The problem is probably in the HTML. The page has content="width=device-width" set which sets the uiWebView content size to the size of the device vs the size of the view.

checkout the second answer to this question displaying Wiki mobile page in UIWebView within UIPopoverController

it fixed my problem The code is below

- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
if(aWebView.frame.size.width < aWebView.window.frame.size.width) {
    // width=device-width results in a wrong viewport dimension for webpages displayed in a popover
    NSString *jsCmd = @"var viewport = document.querySelector('meta[name=viewport]');";
    jsCmd = [jsCmd stringByAppendingFormat:@"viewport.setAttribute('content', 'width=%i, initial-scale=1.0, user-scalable=1');", (NSUInteger)aWebView.frame.size.width];
    [aWebView stringByEvaluatingJavaScriptFromString:jsCmd];
}
// stop network indicator
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

}

Problem

I'm displaying a UIWebView in a UIPopoverController in an iOS application. The iPad is reporting that it's window size is 980x1532. Thus, when I load an external page, it loads and renders 980px wide. I'm hitting an external website in this webview, so I can't modify any code from the server. Is there a way to set it so the iPad UIWebView will report the size of the popover (320x480)?

Original source