如何在iOS 7上更改状态栏背景颜色和文本颜色? [英] How to change the status bar background color and text color on iOS 7?

查看:215
本文介绍了如何在iOS 7上更改状态栏背景颜色和文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的应用程序在iOS 5和6上运行。

My current application runs on iOS 5 and 6.

导航栏为橙色,状态栏为黑色背景色,白色为文本颜色。但是,当我在iOS 7上运行相同的应用程序时,我发现状态栏看起来是透明的,具有与导航栏相同的橙色背景颜色,状态栏文本颜色为黑色。

The navigation bar is having an orange color and the status bar is having a black background color with white text color. However, when I run the same application on iOS 7, I observe the status bar looks transparent with the same orange background color as the navigation bar and the status bar text color is black.

由于这个原因,我无法区分状态栏和导航栏。

Due to this I'm not able to differentiate between the status bar and the navigation bar.

如何使状态栏看起来与iOS 5和6中的状态相同,即黑色背景颜色和白色文本颜色?我怎样才能以编程方式执行此操作?

How do I make the status bar to look the same as it was in iOS 5 and 6, that is with black background color and white text color? How can I do this programmatically?

推荐答案

我必须尝试寻找其他方法。在窗口中不涉及 addSubview 。因为当键盘出现时我正在向上移动。

I had to try look for other ways. Which does not involve addSubview on window. Because I am moving up the window when keyboard is presented.

- (void)setStatusBarBackgroundColor:(UIColor *)color {

    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];

    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
        statusBar.backgroundColor = color;
    }
}



Swift



Swift

func setStatusBarBackgroundColor(color: UIColor) {

    guard  let statusBar = UIApplication.sharedApplication().valueForKey("statusBarWindow")?.valueForKey("statusBar") as? UIView else {
        return
    }

    statusBar.backgroundColor = color
}



Swift 3



Swift 3

func setStatusBarBackgroundColor(color: UIColor) {

    guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return }

    statusBar.backgroundColor = color
}

调用此表单应用程序:didFinishLaunchingWithOptions 为我工作。

NB我们在应用程序商店中有一个具有此逻辑的应用程序。所以我想应用商店政策是可以的。

N.B. We have an app in the app store with this logic. So I guess it is okay with the app store policy.

修改:

使用风险由您自己承担。形成评论者@Sebyddd

Use at your own risk. Form the commenter @Sebyddd


我有一个应用程序拒绝原因,而另一个被接受只需
罚款。他们确实认为它是私有API使用,因此在审核过程中你需要
运气:) - Sebyddd

I had one app rejected cause of this, while another was accepted just fine. They do consider it private API usage, so you are subject to luck during the reviewing process :) – Sebyddd

这篇关于如何在iOS 7上更改状态栏背景颜色和文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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