Reputation: 132
I'm trying to load HTML String containing iframe to UIWebview
the view takes the space of the content but it loads totally blank view here is the HTML
<html>
<head>
<meta http-equiv='Content-Type' content='charset=utf-8'/>
<style>
iframe{max-width:100% !important}
</style>
</head>
<body>
<p dir="RTL"> <iframe allowfullscreen="" frameborder="0" height="573" id="molvideoplayer" scrolling="no" src="http://www.dailymail.co.uk/embed/video/1411595.html" title="MailOnline Embed Player" width="698"></iframe> </p>
</body>
</html>
aslo my code is
self.newsBodyWebView.loadHTMLString(htmlString, baseURL: nil)
Also I tried the UIWebView delegate function
func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {
print(error.localizedDescription)
}
and I got this error
The operation couldn’t be completed. (NSURLErrorDomain error -999.)
I searched the error but nothing helped out.
When I removed the iframe and wrote any other html the UIWebView worked perfectly.
I don't know what's wrong with my code
EDIT
When I press any button to make changes in the container view the webview appears again, I am confused why this happens!
Upvotes: 2
Views: 3704
Reputation: 132
I finally figured it out, the web view height was set after webview finish launching this way
func webViewDidFinishLoad(_ webView: UIWebView) {
webView.frame.size.height = 1
self.webViewHeight = webView.sizeThatFits(CGSize.zero)
}
I changed this to
func webViewDidFinishLoad(_ webView: UIWebView) {
webView.frame.size.height = 1
let height = webView.scrollView.contentSize.height
var wvRect = webView.frame
wvRect.size.height = height
webView.frame = wvRect
}
and every thing is working fine now.
Upvotes: 2