简体   繁体   English

如何使UIWebView的内容适应iPhone的屏幕尺寸?

[英]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. 我创建了一个webView,显示一个对其进行调查的网址,但内容不会缩小到屏幕大小。 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. 应该调整网页的大小以适应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. 您的问题可能是因为webview找不到正确的位置。 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; webView.frame = self.view.frame;

it will make the webview to iphone screen size 它将使webview达到iphone屏幕尺寸

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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