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

查看:29
本文介绍了如何在 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?

推荐答案

警告:它不再适用于 iOS 13 和 Xcode 11.

========================================================================

========================================================================

我不得不尝试寻找其他方法.其中不涉及窗口上的 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;
    }
}

迅捷

func setStatusBarBackgroundColor(color: UIColor) {

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

    statusBar.backgroundColor = color
}

斯威夫特 3

func setStatusBarBackgroundColor(color: UIColor) {

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

    statusBar.backgroundColor = color
}

调用此表单 application:didFinishLaunchingWithOptions 对我有用.

Calling this form application:didFinishLaunchingWithOptions worked for me.

注意我们在应用商店中有一个具有这种逻辑的应用.所以我想应用商店政策没问题.

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天全站免登陆