自定义iOS 7状态栏文本颜色
我想知道是否有方法来改变iOS 7状态栏的文字颜色,除了黑白的颜色?
理论上这是可能的。 你需要阅读关于iOS上的私人API。 这里是开始使用UIStatusBar示例的好地方:
http://b2cloud.com.au/tutorial/using-private-ios-apis/
请记住,如果您使用私有API,您可能无法在Appstore上提交您的应用程序。
把它放在你的AppDelegate应用程序中:didFinishLaunchingWithOptions:
Swift 3.0:
以防万一苹果决定改变这个类的命名(极不可能),我们应该添加一些types安全。
if application.responds(to: Selector(("statusBar"))), let statusBar = application.value(forKey: "statusBar") as? UIView, statusBar.responds(to: Selector(("foregroundColor"))) { statusBar.setValue(UIColor.red, forKey: "foregroundColor") }
Swift 2.0:
application.valueForKey("_statusBar")?.setValue(UIColor.redColor(), forKey: "_foregroundColor")
Objective-C的:
[[application valueForKey:@"_statusBar"] setValue: [UIColor redColor] forKey: @"_foregroundColor"];
很难说您的应用是否会被app store拒绝。 使用KVC访问_statusBar
属性不会让您的应用程序被拒绝,因为UIApplication
类本身并不隐藏。
这就是说, UIStatusBar
类也不是隐藏的,即。 它不在SDK的PrivateFrameworks目录中,也没有用__attribute__((visibility("hidden")))
标记__attribute__((visibility("hidden")))
,类名也不以下划线开头。
如果您的应用程序因使用此function而被拒绝,请在下面留言,以便我可以更新答案。