1. 程式人生 > >計算webView顯示內容後實際高度

計算webView顯示內容後實際高度

- (void)webViewDidFinishLoad:(UIWebView*)wb{
   CGFloat documentWidth = [[wb stringByEvaluatingJavaScriptFromString:@"document.getElementById('content').offsetWidth"] floatValue];

    CGFloat documentHeight = [[wb stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"content\").offsetHeight;"] floatValue];

    NSLog(@"documentSize = {%f, %f}", documentWidth, documentHeight);
    
}
}
第二種:得到了將內容顯示完整後的webView的尺寸(包含UIEdgeInsets)