#import "SubjectViewController.h"@interface SubjectViewController ()@property(nonatomic, strong)UIWebView *webView;@end@implementation SubjectViewController- (void)viewDidLoad { [super viewDidLoad]; self.webView = [self createWeb]; [self.view addSubview:self.webView]
; NSString *htmlString = [NSString stringWithFormat:@"%@", self.info[@"question_html"]]; [self loadHTML:htmlString];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];}- (void)unloadData { self.webView = nil;}- (void)loadHTML:(NSString *)html
{ [self.webView loadHTMLString:html baseURL:nil];}- (UIWebView *)createWeb { UIWebView *web =[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 1)]; web.delegate = self; web.scalesPageToFit = NO; [web.scrollView setShowsHorizontalScrollIndicator:NO];
[web.scrollView setShowsVerticalScrollIndicator:NO]; return web;}- (void)webViewDidFinishLoad:(UIWebView *)webView{ NSString *htmlString = [NSString stringWithFormat:@"%@", self.info[@"question_html"]]; DDLog(@"%@",htmlString); CGFloat documentHeight = [[webView
stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"] floatValue]; DDLog(@"%f", documentHeight); self.webView.frame = CGRectMake(0, 0, kScreenWidth, documentHeight); //document.body.scrollHeight}@end
iOS 计算webview高度
最新推荐文章于 2020-10-19 19:00:04 发布
本文介绍了一个iOS应用中使用UIWebView来加载和显示HTML内容的方法。实现了WebView的初始化配置、HTML字符串的加载及页面加载完成后的处理。此外,还介绍了如何通过JavaScript获取网页的实际高度以适配WebView。
3392

被折叠的 条评论
为什么被折叠?



