【问题标题】:How to fit all the content coming from web services in UIWebView如何在 UIWebView 中适应来自 Web 服务的所有内容
【发布时间】:2012-06-26 13:39:20
【问题描述】:

我已经实现了 UIWebView 并显示来自网络服务的内容,下面是代码

webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,460)];
webView.scalesPageToFit = YES;
webView.dataDetectorTypes = YES;
webView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
webView.delegate = self;

NSURL *targetURL = [NSURL URLWithString:delegate.S_Title];
request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];

但是当我向下滚动到底部时,它并没有滚动显示 webview 显示的完整内容。

【问题讨论】:

    标签: iphone ios objective-c uiwebview


    【解决方案1】:

    试试这个,在UIWebView 中加载内容后,您可以使用它的stringByEvaluatingJavaScriptFromString: 方法来询问html 文档的高度。这有点棘手,但应该可以。

    你可以这样做:

    NSInteger height = [[webView stringByEvaluatingJavaScriptFromString:
        @"document.body.scrollHeight"] integerValue];
    

    滚动高度可能不是最好的。你有几个选择。试验一下here提到的文档属性

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 2013-06-23
      • 1970-01-01
      • 2012-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-03
      相关资源
      最近更新 更多