UIWebView解决加载页面时背景一片空白问题

来源:互联网 发布:山村诡事以知天命 编辑:程序博客网 时间:2024/04/30 12:49

UIWebView加载过程中,在页面没有加载完毕前,会显示一片空白。为解决这个问题,方法如下:

方法1、让UIWebView背景透明。

webView.backgroundColor = [UIColor clearColor];webView.opaque = NO;[webView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"webbg.png"]]];


方法2:

先将webView的frame设为0, 在页面加载完成后再将frame设为原来大小.


方法3:

在viewDidLoad中,在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];

然后在WebView加载完成后把视图放到最上层或移除背景视图。

- (void)webViewDidFinishLoad:(UIWebView *)webView{    // WebView放到最上层    [self.view bringSubviewToFront:self.webView];    // 或者可以把背景图移除    [self.webView removeFromSuperview];}


0 1
原创粉丝点击