简体   繁体   中英

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

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;

尝试使用自动布局:在故事板中选择您的Web视图,然后将自动布局设置为所有4个约束。

write this

webView.frame = self.view.frame;

it will make the webview to iphone screen size

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM