ios - 如何在 iOS 7 上更改状态栏背景颜色和文本颜色?

标签 ios cocoa-touch ios7 uicolor ios-statusbar

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

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

因此,我无法区分状态栏和导航栏。

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

最佳答案

Warning: It does not work anymore with iOS 13 and Xcode 11.

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

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

objective-C

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

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

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

swift

func setStatusBarBackgroundColor(color: UIColor) {

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

    statusBar.backgroundColor = color
}

swift 3

func setStatusBarBackgroundColor(color: UIColor) {

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

    statusBar.backgroundColor = color
}

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

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


编辑:

使用风险自负。形成评论者@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 - 如何在 iOS 7 上更改状态栏背景颜色和文本颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19063365/

相关文章:

iphone - 在 iPhone 上对 double 组或 CLLocationDistance 值进行排序

reference - iOS7创建和使用SKTextureAtlas的正确方法是什么?

iOS 7 Safari 自动收缩/隐藏 UI 元素在滚动时不起作用

ios - Swift如何改变backIndicatorImage的tintColor

iphone - 从 NSKeyedArchiver 加载单例状态

iphone - Apple 在导航 Controller 内延迟加载图像,恢复为占位符图像

iphone - 在导航栏上方添加 View

ios - 如何防止 iOS 消息应用裁剪粘贴的图像?

ios - 从句子中提取名字

objective-c - NSPrivateQueueConcurrencyType上下文只能在performBlock内操作?