首选要等UIWebView加载内容后,然后在它的回调方法里将webview的高度Height设置足够小,就设置为1吧,因为这样才能用sizeThatFits才能计算出webview得内容大小
- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
CGRect frame = aWebView.frame;
frame.size.height = 1;
aWebView.frame = frame;
CGSize fittingSize = [aWebView sizeThatFits:CGSizeZero];
frame.size = fittingSize;
aWebView.frame = frame;
NSLog(@"size: %f, %f", fittingSize.width, fittingSize.height);
}
版权声明:本文为博主原创文章,未经博主允许不得转载。