override func preferredStatusBarStyle() -> UIStatusBarStyle {
return UIStatusBarStyle.LightContent;
}
使用上述代码在任何ViewController中为特定的ViewController设置状态栏颜色为白色,在iOS8中对我来说是行不通的。有什么建议吗?使用UIApplication。shared应用方法,在信息中需要更改后颜色更改。Plist为整个应用程序。
// Change the colour of status bar from black to white
UIApplication.sharedApplication().statusBarStyle = .LightContent
我怎么能改变一些必要的和特定的视图控制器的状态栏颜色?
我遵循了这个教程,它对我很有效。然而,我不确定是否有任何警告。
https://coderwall.com/p/dyqrfa/customize-navigation-bar-appearance-with-swift
打开你的信息。Plist和set
UIViewControllerBasedStatusBarAppearance设为false。
在AppDelegate.swift中的第一个函数中,它包含didFinishLaunchingWithOptions,设置你想要的颜色。
UIApplication.sharedApplication()。statusBarStyle = UIStatusBarStyle。LightContent
Swift 3更新*
共享。statusbarstyle = .lightContent
我在这个问题上遇到了一些麻烦。我不太喜欢在视图中全局改变状态栏的颜色,然后在视图中改变它,然后像接受的答案一样消失。信不信由你,你可以通过在你想要的视图控制器上重写preferredStatusBarStyle来实现。经过很长一段时间,这是我所做的让它工作:
Change View controller-based status bar appearance in your info.plist to YES.
Now any full screen view controller can change the status bar style by overriding preferredStatusBarStyle.
I specify full screen because this will not work for (non-full screen) modal view controllers, not without setting modalPresentationCapturesStatusBarAppearance to Yes that is.
Also if you have embedded view controllers, like in a navigation controller for example, it will ask the top most view controller for status bar style. Overriding childViewControllerForStatusBarStyle and passing the embedded view controller is supposed to work but it didn't for me. So I just returned the embedded view controllers preferred status bar as the preferred status bar style. Something like this:
override var preferredStatusBarStyle: UIStatusBarStyle {
if let topViewController = viewControllers.last {
return topViewController.preferredStatusBarStyle
}
return .default
}