Take the 2-minute tour ×

I have an app I am working on in Xcode. Part of the app area loads an html file. The HTML file itself has some links to external websites. They open fine, except they are not scaled to fit on the iPhone.

How would I go about ensuring all web pages opened are scaled to fit? The code from the .m file is below

NSString *fileString = [[NSBundle mainBundle] pathForResource: @"chapter5" ofType: @"html"];



[webview loadRequest: newURLRequest];

The HTML file "chapter5.html contains links to websites.

I thought I would try entering

webview.scalesPageToFit = YES

in the .m file hoping it would apply to anything opened, but that didn't work.

Any advice would be greatly appreciated.


share|improve this question

3 Answers 3

The scalesPageToFit will take effect only when the webView loads the request. Implement the delegate of UIWebView webViewDidFinishLoad: method and try this code.

- (void)webViewDidFinishLoad:(UIWebView *)webView
    CGSize defaultSize = webView.frame.size;
    CGSize fittingSize = [tableViewCell.webView sizeThatFits:defaultSize];
    [webView sizeThatFits:fittingSize];

    NSLog(@"Size : %@",NSStringFromCGSize(fittingSize));
share|improve this answer

Please set webview mode as Aspect-Fit

share|improve this answer

Thanks guys, I set webview mode as Aspect-Fit and set the Scaling to scale pages to fit and this worked, not sure how I missed that.

share|improve this answer

Your Answer


