I have a question. I have a menu, when I click on it, it will load content remotely from URL via UIWebView.
When I try on simulator, before loading the content, there's a white background and then loads my HTML Page (which has dark background)
Demo:
You can see that white flash, when I click on "KALENDER"
How can I fix this issue?
My UIWebView looks like this:
let myWebView:UIWebView = UIWebView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height))
myWebView.loadRequest(NSURLRequest(URL: NSURL(string: "http://website.com/test.html")!))
self.view.addSubview(myWebView)
Thank you!
So, what I did, is, added:
myWebView.opaque = false
myWebView.backgroundColor = UIColor.clearColor()
and at controller, I unchecked this from "View"
You cannot set background color to your webView.
You should try following steps:
1. write following in your viewDidLoad - Setting delegate and hiding webView.
webView.delegate = self
webView.hidden = YES
2. Write delegate - shouldStartLoadWithRequest
- hiding webView when loading starts.
func webView(webView: UIWebView!, shouldStartLoadWithRequest request: NSURLRequest!, navigationType: UIWebViewNavigationType) -> Bool {
webView.hidden = YES
return true;
}
3. Write delegate - webViewDidFinishLoad
- Show webView when loading Ends.
func webViewDidFinishLoad(webView: UIWebView!) {
webView.hidden = NO
print("Webview did finish load")
}
Hope this will help you....
You could load your own html document, which uses the color you need.
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
let htmlString = "<html><body bgcolor=\"#ABCDEF\"></body></html>"
webView.loadHTMLString(htmlString, baseURL: nil)
}