zoukankan      html  css  js  c++  java
  • 计算 webView 显示内容后实际高度

    两种方法,方法1可以得到内容的实际高度,方法2得到了将内容显示完整后的 webView 的尺寸(包含 UIEdgeInsets)

    - (void)webViewDidFinishLoad:(UIWebView *)wb
    
    {
    
        //方法1
    
        CGFloat documentWidth = [[wb stringByEvaluatingJavaScriptFromString:@"document.getElementById('content').offsetWidth"] floatValue];
    
        CGFloat documentHeight = [[wb stringByEvaluatingJavaScriptFromString:@"document.getElementById("content").offsetHeight;"] floatValue];
    
        NSLog(@"documentSize = {%f, %f}", documentWidth, documentHeight);
    
        //方法2
    
        CGRect frame = wb.frame;
    
        frame.size.width = 768;
    
        frame.size.height = 1;
    
        //    wb.scrollView.scrollEnabled = NO;
    
        wb.frame = frame;
    
        frame.size.height = wb.scrollView.contentSize.height;
    
        NSLog(@"frame = %@", [NSValue valueWithCGRect:frame]);
    
        wb.frame = frame;
    
    }
  • 相关阅读:
    Hibernate 查询语句
    application 网站计数器
    Hibernate 配置
    常用正则表达式
    字符串的系列操作
    输入内容验证
    大小写字母验证
    验证非零的正整数
    验证数字输入
    Java面向对象之多态
  • 原文地址:https://www.cnblogs.com/sungk/p/5170814.html
Copyright © 2011-2022 走看看