【问题标题】:stringByEvaluatingJavaScriptFromString recognize webview content heightstringByEvaluatingJavaScriptFromString 识别 webview 内容高度
【发布时间】:2012-05-11 14:38:31
【问题描述】:

我在 UIscrollview 中放置了一个 Uiwebview,因为在 uiwebview 之后我想用 PageController 显示一些图像。

我正在使用这行代码。

   -(void)webViewDidFinishLoad:(UIWebView *)webView{
    if (webView!=WebView)return;
    float h;

    NSLog(@"web view is %f high", WebView.frame.size.height);
    NSString *heightString = [WebView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"body\").offsetHeight;"];
    NSLog(@"web content is %@ high",heightString);

    h = [heightString floatValue] +12.0f;   
    WebView.frame = CGRectMake(WebView.frame.origin.x, WebView.frame.origin.y, WebView.frame.size.width, h);

    h = WebView.frame.origin.y + h + 20; 
    [ScrollView setContentSize:CGSizeMake(320, h)];


}

但是Web view is %f high 不起作用,它不能重新调整 WebView 的高度有谁知道我该如何解决这个问题?这是因为我使用的是[WebView loadHTMLString:html baseURL:nil];

还有:NSString *heightString = [WebView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"body\").offsetHeight;"];

 NSString *html = [NSString stringWithFormat:@"<html><head><!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><style>body {  font: normal 13px helvetica; color: #565656;   } </style></head><body><p>%@</p></body></html> ",text];  


[WebView loadHTMLString:html baseURL:nil];

【问题讨论】:

    标签: objective-c xcode cocoa ios5


    【解决方案1】:

    试试

    NSString *heightString = [Bericht stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"];
    

    祝你好运, 内森

    【讨论】:

    【解决方案2】:

    UIWebView 已经包含了一个scrollView,为什么还要把它添加为子视图。查看苹果的文档here

    【讨论】:

    • 因为他想在他的 UIWebview 下显示(UIPageControl)图像?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    • 2015-03-04
    • 2017-10-18
    • 1970-01-01
    • 2019-06-16
    相关资源
    最近更新 更多