欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

UIWebView解决加载页面时背景一片空白问题_html/css_WEB-ITnose

程序员文章站 2024-01-02 08:30:04
...
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];}

上一篇:

下一篇: