有时候需要展示课程的介绍,往往是一些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];
}
网友评论