如何在向下滑动UIWebView以修复iOS7状态栏覆盖问题后更改UIWebView背景颜色? [英] How can I change the UIWebView background color after sliding down UIWebView to fix the iOS7 status bar overlay issue?

查看:159
本文介绍了如何在向下滑动UIWebView以修复iOS7状态栏覆盖问题后更改UIWebView背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个Phonegap 3.0+应用程序。



iOS7中的状态栏重叠显示有一个问题,用户

UIWebView背景设置为清除颜色,但不透明




下面是我尝试过的代码到目前为止:

   - (void)viewWillAppear:(BOOL)animated {
// ios 7
if([[[UIDevice currentDevice] systemVersion] floatValue]> = 7){
CGRect viewBounds = [self.webView bounds];
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height - 20;
self.webView.frame = viewBounds;
[self.webView setOpaque:YES];

//取消注释时,这两个都不起作用:
// [self.webView setBackgroundColor:[UIColor grayColor]];
// self.webView.backgroundColor = [UIColor grayColor];
}
[super viewWillAppear:animated];
}




< hr>

UPDATE 1

   - (void) viewWillAppear:(BOOL)animated 
{
// ios 7上的下屏幕20px
if([[[UIDevice currentDevice] systemVersion] floatValue]> = 7){
CGRect viewBounds = [self.webView bounds];
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height - 20;
self.webView.frame = viewBounds;

self.webView.backgroundColor = [UIColor grayColor];
self.webView.opaque = NO;
}
[super viewWillAppear:animated];
}

这似乎还给我一个白色背景的状态栏,灰色。



我希望的结果是这样的:

解决方案

所以我意识到代码推动UIWebView下降20px。意思是根据定义的空格不能是UIWebView。白色空间是主视图,我通过执行以下操作来更改背景颜色:



1。转到MainViewController.xib:



< br>
2。选择主视图:




3。显示属性检查器并更改颜色。已完成。



显然现在我想想,但希望这有助于未来的人。


I'm writing a Phonegap 3.0+ app.

There is an issue with the status bar overlapping views in iOS7 which user Ludwig Kristoffersson provided a working answer here

Now that I have UIWebView with a 20px top margin, how can I change the UIWebView background color? I need the area behind the status bar to be the same background color as the "people" toolbar.

I have almost no experience in Objective C, and have been looking through possible SO questions to find a working solution but with no success.

UIWebView background color
UIWebView background is set to Clear Color, but it is not transparent


Below is the code that I've tried so far:

- (void)viewWillAppear:(BOOL)animated {
    //Lower screen 20px on ios 7
    if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        CGRect viewBounds = [self.webView bounds];
        viewBounds.origin.y = 20;
        viewBounds.size.height = viewBounds.size.height - 20;
        self.webView.frame = viewBounds;
        [self.webView setOpaque:YES];

        //neither of these seem to work when uncommented:
  //    [self.webView setBackgroundColor:[UIColor grayColor]];
  //    self.webView.backgroundColor=[UIColor grayColor];
        }
    [super viewWillAppear:animated];
    }



UPDATE 1

- (void)viewWillAppear:(BOOL)animated
{
//Lower screen 20px on ios 7
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    CGRect viewBounds = [self.webView bounds];
    viewBounds.origin.y = 20;
    viewBounds.size.height = viewBounds.size.height - 20;
    self.webView.frame = viewBounds;

    self.webView.backgroundColor = [UIColor grayColor];
    self.webView.opaque=NO;
}
[super viewWillAppear:animated];
}

That still seems to give me a white background behind the status bar, rather than gray.

The result I'm hoping for is like this:

解决方案

So I realized that the code pushes the UIWebView down 20px. Meaning that the white space by definition cannot be UIWebView. The white space is the main view which I changed the background color by doing the following:

1. Go to MainViewController.xib:



2. Select the main view:


3. Show the attributes inspector and change the color. Done.

Obvious now that I think about it, but hopefully this helps someone in future.

这篇关于如何在向下滑动UIWebView以修复iOS7状态栏覆盖问题后更改UIWebView背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆