English 中文(简体)
IDWeb 意见不表示内容适合
原标题:UIWebView does not scale content to fit
  • 时间:2009-10-02 20:44:04
  •  标签:

我有一个网站概览,是等级结构中最大的窗口,已宣布如下。 然而,它并不适合页数。 尽管向YES设定了“Fage ToFit”财产,但页数没有调整。 任何帮助都将受到高度赞赏。

webLookupView = [[UIWebView alloc] initWithFrame:CGRectMake(16, 63, 289, 327)];
webLookupView.backgroundColor = [UIColor lightGrayColor];
webLookupView.dataDetectorTypes = UIDataDetectorTypeAll;
webLookupView.scalesPageToFit = YES;
最佳回答

我后来发现,一些网页被正确地缩小,但有些网页没有。 对于没有适当规模的网页,可使用java字母控制如下的分流:

NSString *jsCommand = [NSString stringWithFormat:@"document.body.style.zoom = 1.5;"];
[webLookupView stringByEvaluatingJavaScriptFromString:jsCommand];
问题回答

第5号协议提供了更好的解决办法

“DidFinishLoad”

- (void)zoomToFit
{ 
    if ([theWebView respondsToSelector:@selector(scrollView)])
    {
        UIScrollView *scrollView = [theWebView scrollView];

        float zoom = theWebView.bounds.size.width / scrollView.contentSize.width;
        scrollView.minimumZoomScale = zoom;
        [scrollView setZoomScale:zoom animated:YES];
    }
}

您可使用以下法典:

self.webView.scalesPageToFit = YES;
self.webView.contentMode = UIViewContentModeScaleAspectFit;

in - (void)webViewDidFinishLoad:(UIWebView *)webView method or viewDidLoad

如果你能够接触到html,你可以装上以下 met子:

<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />

页: 1

self.webView.scalesPageToFit = true
self.webView.contentMode = UIViewContentMode.ScaleAspectFit

我的迅速解决办法:

需要在界面建筑商中检查网上“适合”的“销售页面”。

Use UIWebViewDelegate.

func webViewDidFinishLoad(webView: UIWebView) {
    let zoom = webView.bounds.size.width / webView.scrollView.contentSize.width
    webView.scrollView.setZoomScale(zoom, animated: true)
}

http://stackoverflow.com/users/1281407/mprivat"。 您可以更新“IDWeb”号。

- (void)webViewDidFinishLoad:(UIWebView *)theWebView {
  CGSize contentSize = theWebView.scrollView.contentSize;
  CGSize viewSize = theWebView.bounds.size;

  float rw = viewSize.width / contentSize.width;

  theWebView.scrollView.minimumZoomScale = rw;
  theWebView.scrollView.maximumZoomScale = rw;
  theWebView.scrollView.zoomScale = rw;  
}

实现这一目的的另一个途径是,在网上的LovidFinish Load上采用“js”法,作为。 说了。

- (void)webViewDidFinishLoad:(UIWebView *)webView {
  CGFloat scale = 0.8; // the scale factor that works for you 
  NSString *js = [NSString stringWithFormat:@"document.body.style.zoom = %f;",scale];
  [webView stringByEvaluatingJavaScriptFromString:js];
}

查阅<代码>WKWebView回答的人,请查阅以下代码:

extension YourViewController: WKNavigationDelegate {

    func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
        let jscript = "var meta = document.createElement( meta ); meta.setAttribute( name ,  viewport ); meta.setAttribute( content ,  width=device-width ); document.getElementsByTagName( head )[0].appendChild(meta);"
        webView.evaluateJavaScript(jscript)
    }
}

指定网站概览的<代码>navigationDelegate。

<Swift 3,RunLoop

self.webView.stringByEvaluatingJavaScript(from: "document.body.style.zoom = 1.5;")

在XCode 8.3.3中,查看了网站浏览点的图像板,并检查了属地督察科的版面。 还选定Fill表作为内容模式。

请参看<>viewDidLoad。

[self.myWebView setFrame:CGRectMake(self.view.frame.origin.x,
                                   self.view.frame.origin.y,
                                   self.view.frame.size.width,
                                   self.view.frame.size.height)];
  • I also have the webview set to "scalePageToFit" and viewmode set to "Aspect Fit" in my Storyboard.




相关问题
热门标签