上代码
@property (nonatomic, strong) UIWebView *webView;
@property (nonatomic, assign) CGFloat footerHeight;
- (UIWebView *)webView {
if (!_webView) {
_webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 500)];
_webView.delegate = self;
_webView.scrollView.scrollEnabled = NO;
_webView.scrollView.showsVerticalScrollIndicator = NO;
_webView.scrollView.showsHorizontalScrollIndicator = NO;
}
//获取接口返回的html 我这个需要拼接<html><body> </body></html>
//<style>img{width:100%% !important;}</style> 用于适配图片大小 宽度为屏宽 高度自适应
NSString * htmlString = [NSString stringWithFormat:@"<html><body><style>img{width:100%% !important;}</style> %@ </body></html>",self.dataModel.content];
[_webView loadHTMLString:htmlString baseURL:nil];
return _webView;
}
#pragma mark -- UIWebViewDelegate
- (void)webViewDidFinishLoad:(UIWebView *)webView {
self.footerHeight = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] floatValue];
webView.frame = CGRectMake(0, 0, SCREEN_WIDTH, _footerHeight);
[self.tableView beginUpdates];
[self.tableView.tableFooterView addSubview:webView];
[self.tableView endUpdates];
}
#pragma mark -- UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return self.footerHeight;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *footerView = nil;
footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.footerHeight)];
[footerView addSubview:self.webView];
return footerView;
}
注释:我这里是将UIWebView添加在了tableView的foot上