ios UIWebView 展示HTML代码(UITableView 中添加webview 动态计算高度)
2017-08-04 11:36
513 查看
上代码
@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上
相关文章推荐
- iOS - UITableView cell中添加展开关闭的功能(cell高度动态变化)
- iOS计算UIWebView的高度和iOS8之后的WKWebView的高度问题
- iOS计算UIWebView的高度和iOS8之后的WKWebView的高度问题
- iOS计算UIWebView的高度和iOS8之后的WKWebView的高度问题
- ios TableView那些事(三十 五)TableView 单选操作使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- iOS 计算webview高度
- 关于IOS UITableView的动态高度问题
- iOS UITableView Cell动态高度(使用AutoLayout)
- Swift iOS tableView static cell动态计算高度
- IOS 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- iOS Cell子视图添加约束后,动态计算Cell高度
- 亲测!最方便的计算UIWebView的高度和iOS8之后的WKWebView的高度方法
- iOS UITableView+FDTemplateLayoutCell 配合AutoLayout分分钟教你实现动态高度自适应
- iOS动态改变UITableView的tableViewHeader的高度
- iOS开发-UI控件:动态改变UITableView中的Cell高度
- UITableView 如何不动态计算返回的cell 的高度
- Swift iOS tableView static cell动态计算高度
- iOS UITableView Cell的动态高度实现
- iOS 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- iOS webView展示gif图(登录时背景图动态gif)