美文网首页
IOS开发UIWebView获取页面动态高度

IOS开发UIWebView获取页面动态高度

作者: MrBan | 来源:发表于2018-07-09 18:06 被阅读0次

上一段代码大家体会一下。

UIWebView *webView =[[UIWebView alloc]initWithFrame:CGRectMake(0,kScreenWidth*300/375 +128,kScreenWidth,self.view.height-49-44)];

    NSString *content =[item.note stringByReplacingOccurrencesOfString:@""" withString:@"'"];

    content =[content stringByReplacingOccurrencesOfString:@"<" withString:@"<"];

    content =[content stringByReplacingOccurrencesOfString:@">" withString:@">"];

    content =[content stringByReplacingOccurrencesOfString:@""" withString:@"\""];

    NSString *htmls =[NSString stringWithFormat:@" \n"

                       " \n"

                       " \n"

                       " \n"

                       "body {font-size:15px;}\n"

                       " \n"

                       " \n"

                       ""

                       ""

                       "window.onload = function(){\n"

                       "var $img = document.getElementsByTagName('img');\n"

                       "for(var p in  $img){\n"

                       " $img[p].style.width = '100%%';\n"

                       "$img[p].style.height ='auto'\n"

                       "}\n"

                       "}"

                       "%@"

                       ""

                       "",content];

    [webView loadHTMLString:htmls baseURL:nil];

    webViewHeight =[[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"]floatValue]/2+40;

相关文章

网友评论

      本文标题:IOS开发UIWebView获取页面动态高度

      本文链接:https://www.haomeiwen.com/subject/vfvtpftx.html