How do I make a UIWebView's content adjust to the iPhone screen size?

25,972

The statement

webView.scalesPageToFit = YES;

should size the web page to fit the size of the UIWebView. The user then has the option to zoom in and out of the page. Your problem might be because the webview is not located properly. If your view controller's view fits the screen entirely, add this to your code.

webView.frame=self.view.bounds;
Share:
25,972
michael03m
Author by

michael03m

Updated on July 22, 2020

Comments

  • michael03m
    michael03m almost 4 years

    I know there a lot of similar questions to this, but I didn't find any that helped me out. I made a webView that displays a url that has a survey on it, but the content isn't shrinking to the size of the screen. Can somebody tell me what I need to write to just get the content to shrink to the screen size, and where I put it? Any help would be greatly appreciated.

    - (void)viewDidLoad
    {
        NSString *website =@"http://www.nameofwebsite.com";
        NSURL *url = [NSURL URLWithString:website];
        NSURLRequest *requestURL =[NSURLRequest requestWithURL:url];
        webView.scalesPageToFit = YES;
        webView.autoresizesSubviews = YES;    
        [webView loadRequest:requestURL];
    
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
  • michael03m
    michael03m about 12 years
    Thanks a lot! The webView.frame=self.view.bounds; is what I was missing.
  • Lena Bru
    Lena Bru almost 10 years
    this doesnt help me though :(