I have a WKWebView inside a UITableViewCell, which loads an HTML string (I have embedded a tweet).
I have tried all types of solutions on Stack Overflow, but they didn't work for me. Here is an example of something I tried:
class DetailWebCell: UITableViewCell {
@IBOutlet weak var detailWebView: WKWebView!
@IBOutlet weak var containerHeight: NSLayoutConstraint!
override func awakeFromNib() {
super.awakeFromNib()
detailWebView.scrollView.isScrollEnabled = false
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
self.detailWebView.evaluateJavaScript("document.readyState", completionHandler: { (complete, error) in
if complete != nil {
self.detailWebView.evaluateJavaScript("document.body.scrollHeight", completionHandler: { (height, error) in
self.containerHeight.constant = height as! CGFloat
})
}
})
}
}
But the cell's height remains the same
I want the height of the WKWebview to be the same height as the tableView Cell's
try this
self.containerHeight.constant = detailWebView.scrollView.contentSize.height
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