gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 07:30:57 25 4
gpt4 key购买 nike

我当前的应用程序在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com