代码淘沙0622(C-获取webView内容高度)

2017-06-22  本文已影响13人  大风起兮_Seven

有时候需要展示课程的介绍,往往是一些html,需要获取webView的高度进行一些调整

//题目介绍内容
NSString * htmlcontent = [NSString stringWithFormat:@"<div id=\"webview_content_wrapper\">%@</div>", courseModel.content];
[webView loadHTMLString:htmlContent baseURL:nil];
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    NSString * height_str= [webView  stringByEvaluatingJavaScriptFromString: @"document.getElementById('webview_content_wrapper').offsetHeight + parseInt(window.getComputedStyle(document.getElementsByTagName('body')[0]).getPropertyValue('margin-top'))  + parseInt(window.getComputedStyle(document.getElementsByTagName('body')[0]).getPropertyValue('margin-bottom'))"];
    float height = [height_str floatValue]==16 ? 0:[height_str floatValue];
}
上一篇 下一篇

猜你喜欢

热点阅读