在向下滑动UIWebView以修复iOS7状态栏覆盖问题后,如何更改UIWebView背景颜色?

栏目: IOS · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/19417058/how-can-i-change-the-uiwebview-background-color-after-sliding-down-uiwebview-to

我正在写一个Phonegap 3.0应用程序.

iOS7中的状态栏重叠视图存在问题,即用户 Ludwig Kristoffersson provided a working answer here

现在我的UIWebView具有20px的上边距,我该如何更改UIWebView背景颜色?我需要状态栏后面的区域与“人物”工具栏的背景颜色相同.

我几乎没有Objective C的经验,并且一直在寻找可能的SO问题来找到一个有效的解决方案,但没有成功.

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

- (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];
    }

更新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];
}

这似乎仍然给我一个状态栏背后的白色背景,而不是灰色.

我希望的结果是这样的:

将Opaque属性更改为NO并检查如下:

self.webView.backgroundColor = [UIColor grayColor];
self.webView.opaque=NO;

它对我来说很好.

翻译自:https://stackoverflow.com/questions/19417058/how-can-i-change-the-uiwebview-background-color-after-sliding-down-uiwebview-to


以上所述就是小编给大家介绍的《在向下滑动UIWebView以修复iOS7状态栏覆盖问题后,如何更改UIWebView背景颜色?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Spring

Spring

Bruce Tate、Justin Gehtland / O'Reilly Media, Inc. / 2005-04-12 / USD 29.95

Since development first began on Spring in 2003, there's been a constant buzz about it in Java development publications and corporate IT departments. The reason is clear: Spring is a lightweight Java......一起来看看 《Spring》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

SHA 加密
SHA 加密

SHA 加密工具