Customize iOS 7 status bar text Color

ぃ、小莉子 提交于 2019-12-18 09:07:32

问题


I want to know if there is a way to change the iOS 7 status bar text color besides black and white color?


回答1:


Theoretically this is possible. You will need to read about private api's on iOS. Here is o good place to start with UIStatusBar example:

http://b2cloud.com.au/tutorial/using-private-ios-apis/

Keep in mind that probably you won't be able to submit your app on Appstore if you would use private api.




回答2:


Put this in your AppDelegate application:didFinishLaunchingWithOptions:

Swift 4.2:

if UIApplication.shared.responds(to: Selector(("statusBar"))),
    let statusBar = UIApplication.shared.value(forKey: "statusBar") as? UIView,
    statusBar.responds(to: #selector(getter: CATextLayer.foregroundColor)) {
    statusBar.setValue(UIColor.red, forKey: "foregroundColor")
}

Swift 3.0:

Just in case Apple decides to change the naming of the class (highly unlikely) we shall add some type-safety.

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"];

It's hard to say if your app will be rejected from the app store. Using KVC to access the _statusBar property will not get your app rejected as the UIApplication class itself is not hidden.

That being said, neither is the UIStatusBar class hidden, ie. it's not in the SDK's PrivateFrameworks directory nor marked with __attribute__((visibility("hidden"))) nor does the class name begin with an underscore.

If your app was rejected because of using this please comment below so I can update the answer.



来源:https://stackoverflow.com/questions/25053844/customize-ios-7-status-bar-text-color

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!