iOS webView 加载HTML5获取加载后的高度

第一种


//html5 图片设置为屏幕宽
        NSString *myStr = [NSString stringWithFormat:@"",screenWidth];
        NSString *str = [NSString stringWithFormat:@"%@%@",myStr,html5文本];

//
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    //HTML5的高度
    NSString *htmlHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"];
    //HTML5的宽度
    NSString *htmlWidth = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollWidth"];
   //宽高比
    float i = [htmlWidth floatValue]/[htmlHeight floatValue];
   
    //webview控件的最终高度
    float height = screenWidth/i;

    //后面的代码
    。。。。。。
    
}


第二种

        NSString *htmls = [NSString stringWithFormat:@" \n"
                           " \n"
                           " \n"
                           " \n"
                           ""
                           "%@"
                           ""
                           "",_model.content];
        [_webView loadHTMLString:htmls baseURL:nil];



- (void)webViewDidFinishLoad:(UIWebView *)webView{
    
    NSString *htmlHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"];
    NSString *htmlWidth = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollWidth"];
    
    float i = [htmlWidth floatValue]/[htmlHeight floatValue];
  
  float height = screenWidth/i;
    //
    //后面的代码
    。。。。。。

}




你可能感兴趣的:(webView)