This problem is encountered in the project: WebView load the local HTML Uiscrollview,webview, and then you need to calculate the webview height.
The steps are as follows:
1. First create the WebView. Note that the height must be less than the height of the HTML you want to load, preferably set a minimum value, such as 1, and set scalespagetofit = yes to make it adaptive height;
Self.bottomwebview = [[UIWebView alloc]initwithframe:cgrectmake (0, Cgrectgetmaxy (self.middleView3.frame) + Ksectioninterval, Kscreenwidth,)]; Self.bottomWebView.layer.borderColor = Self.topView.layer.borderColor; Self.bottomWebView.layer.borderWidth = Self.topView.layer.borderWidth; Self.bottomWebView.scalesPageToFit = YES;
2. The second is displayed in the controller. Set up the agent, load H5
Self.recordScrollView.bottomWebView.delegate = self; [Self loadH5WithId:self.check.checkId]; [Self.view AddSubview:self.recordScrollView];
3. Load h5
NSString *path = [[NSBundle mainbundle] pathforresource:[nsstring stringwithformat:@ "cj%d.htm", (int) CheckId + 1] OfType : nil]; NSString *htmlstring = [NSString stringwithcontentsoffile:path encoding:nsutf8stringencoding Error:nil]; Nsurl *baseurl = [Nsurl Fileurlwithpath:path]; [Self.recordScrollView.bottomWebView loadhtmlstring:htmlstring Baseurl:baseurl];
4. Calculate Height in Agent method
-(void) Webviewdidfinishload: (UIWebView *) webview{ float webviewheight = [[WebView Stringbyevaluatingjavascriptfromstring: @ "Document.body.scrollHeight"] floatvalue]; Webview.frame = CGRectMake (Cgrectgetminx (Webview.frame), Cgrectgetminy (Webview.frame), CGRectGetWidth ( Webview.frame), webviewheight); webView.scrollView.scrollEnabled = NO; float heightsum = Cgrectgetminy (webview.frame) + webviewheight + 15;//15 increment self.recordScrollView.contentSize = Cgsizemake (Kscreenwidth, heightsum); }
This allows you to adapt to the height of your own.
iOS development _uiwebview loading local HTML