I use a UIWebView
to show an "About" screen by displaying a bundled HTML file. My app's view hierarchy is: UITabBarController
/ UIViewController
/ UIWebView
.
The problem is that the HTML page has a dark background, and the very first time the tab is tapped, a white background is visible briefly before the web view is displayed. I tried setting the background color of the UIWebView
, but that doesn't solve the problem. The problem occurs whether I load the content in viewDidLoad
or viewWillAppear
.
Swift:
webView.isOpaque = false webView.backgroundColor = UIColor.clear
Objective-C:
webView.opaque = NO; webView.backgroundColor = [UIColor clearColor];
// load index.html
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www"]];
self.webview.delegate = self;
self.webview.alpha = 0; // flicker fix
[self.webview loadRequest:[NSURLRequest requestWithURL:url]];
Add this to delegate after loading
// flicker fix
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.30];
self.webview.alpha = 1;
[UIView commitAnimations];
}
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