Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.
}
like image 465
michael03m Avatar asked Mar 22 '12 00:03

michael03m


1 Answers

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;
like image 158
MadhavanRP Avatar answered Sep 19 '22 06:09

MadhavanRP