I am creating on an application using Objective C, where I'm using a UIWebView
to display contents in HTML format. I am using below code in UIWebView
delegate method webViewDidFinishLoad
NSUInteger contentHeight = [[aWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.body.scrollHeight;"]] intValue];
to calculate the webview content height, this is working fine in iOS8
, iOS9
and iOS11
but in iOS10
iPhone mobiles the content height returning a much bigger value than the actual content value. Because of this, I am getting some extra white space in bottom of my webview in screen.
I tried all the solutions but getting the same wrong content height only in iOS 10. Please help me to resolve this problem. Thank You in Advance!
I had used following way to get contentSize.
i have added observer(KVO) on webview's scrollview.
self.webView.scrollView.addObserver(self, forKeyPath: "contentSize", options: .new, context: nil);
Now, whenever contentsize of webview will get changed, i get callback in this method
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
}
Now take the contentSize of object from this method and use that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With