michael03m
michael03m

Reputation: 161

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.
}

Upvotes: 11

Views: 26282

Answers (3)

BrainyMonkey
BrainyMonkey

Reputation: 31

Try using auto layout:Select your web view in your storyboard then set auto layout to all 4 constraints.

Upvotes: 0

MadhavanRP
MadhavanRP

Reputation: 2830

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;

Upvotes: 26

Manish Agrawal
Manish Agrawal

Reputation: 11026

write this

webView.frame = self.view.frame;

it will make the webview to iphone screen size

Upvotes: 0

Related Questions