Home > Article > Web Front-end > UIWebView solves the problem of blank background when loading the page_html/css_WEB-ITnose
During the loading process of UIWebView, a blank page will be displayed before the page is loaded. To solve this problem, the method is as follows:
Method 1. Make the UIWebView background transparent.
webView.backgroundColor = [UIColor clearColor];webView.opaque = NO;[webView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"webbg.png"]]];
Method 2:
First set the frame of webView to 0, on the page After loading is complete, set the frame to its original size.
Method 3:
In viewDidLoad, overlay a background view on the WebView.
self.webView=[[[UIWebView alloc]initWithFrame:self.view.bounds]autorelease]; [self.webView loadRequest:request]; [self.view addSubview:self.webView]; UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"gatewaybg.png"]]; imageView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); [self.view addSubview:imageView];
- (void)webViewDidFinishLoad:(UIWebView *)webView{ // WebView放到最上层 [self.view bringSubviewToFront:self.webView]; // 或者可以把背景图移除 [self.webView removeFromSuperview];}