开发者

iphone uiwebview initial white view

开发者 https://www.devze.com 2022-12-24 04:14 出处:网络
My app\'s main view has a uiwebview. It is white for a split second before it has time to render the HTML the app generates.

My app's main view has a uiwebview. It is white for a split second before it has time to render the HTML the app generates.

Is there a way to make the uiwebview black, or another color, before it renders? The flash of white isn't part of m开发者_如何学Goy plan for a smooth visual transition.

Objective-C or MonoTouch answers are fine, I am bi-lingual.


Another thing to try is to make the view transparent:

webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;

This causes additional compositing work, however, so you can reset these values to something more friendly for that after your web view loads, in webViewDidFinishLoad:.

- (void) webViewDidFinishLoad:(UIWebView *)webView
{
    webView.backgroundColor = [UIColor blackColor];
    webView.opaque = YES;
}


One thing you can try is put a UIView with the color you want and position it above the UIWebView with the same width and height. Then in the webViewDidFinishLoad method, set the UIView to hidden.


I can't comment yet hence the answer. @Steve, actually it's possible to do with storyboards.

Place a UIView under the UIWebView and:

// Can be set in the storyboard
bottomView.backgroundColor = [UIColor yellowColor];
webview.alpha = 0;

Keep in mind that a lot of page fetch stuff after being loaded via JS so you still can be left with a white page couple seconds after

- (void) webViewDidFinishLoad:(UIWebView *)webView
{
    webView.alpha = 1;
}


To add to Steve Madsen's answer (since I can't comment yet). If you instanced the UIWebView in Interface Builder, you wont be able to set alpha to 0.0, but what you can do is bring up the color picker to set a background color (white, black, gray, it doesnt matter), then set the opacity of that color to zero percent, and that works.

0

精彩评论

暂无评论...
验证码 换一张
取 消