UIWebView实际内容高度?

时间:2015-04-10 08:11:23

标签: ios objective-c uiwebview

我已经采用了网络视图并加载了像这样的HTML

NSMutableString *myDescriptionHTML = [NSMutableString stringWithFormat:@"<html> \n"
   "<head> \n"
   "<style type=\"text/css\"> \n"
   "body {font-family: \"%@\"; font-size: %@;}\n"
   "</style> \n"
   "</head> \n"
   "<body>%@</body> \n"
   "</html>", @"helvetica", [NSNumber numberWithInt:40], messageModel.content];

我想在Web视图加载的html内容

之后将Web视图高度设置为Web视图内容大小高度

尝试方式

1)

CGRect frame = self.webViewMain.frame;
frame.size.height = 1;
self.webViewMain.frame = frame;
CGSize fittingSize = [self.webViewMain sizeThatFits:CGSizeZero];
frame.size = fittingSize;
self.webViewMain.frame = frame;
Height = fittingSize.height;
NSLog(@"size: %f, %f", fittingSize.width, fittingSize.height);
[tableViewMain reloadData];

它太长了

2)

Height = [[self.webViewMain stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight;"] floatValue]; 

3)

Heiht = self.webViewMain.scrollView.contentSize.Height

但没有人是实际身高

帮我谢谢....

1 个答案:

答案 0 :(得分:0)

UIWebview是UIScrollview的子类,因此您可以使用CGSize设置Webview.content大小。这将根据需要设置您的Web视图内容高度和宽度。

相关问题