extension UIViewController {
// utility to set the status bar appearance
// Note: Make sure "View controller-based status bar appearance" is set to NO in your target settings or this won't work
func setStatusBarForDarkBackground(dark: Bool) {
UIApplication.sharedApplication().statusBarStyle = dark ? .LightContent : .Default
setNeedsStatusBarAppearanceUpdate()
}
}
9 回答
在viewDidLoad方法上,输入:
目标C.
迅速
EDIT: This solution is deprecated on iOS 9. Please choose one of the other answers.
将
UIViewControllerBasedStatusBarAppearance
设置为NO,我可以使用以下方法将样式设置为白色文本:这是因为此样式的文本颜色在iOS 6及更低版本上为白色 .
UPDATE: 根据@jowie你可以在iOS8上试试:
你试过这个吗?
在Info.plist中将"View controller-based status bar appearance"(
UIViewControllerBasedStatusBarAppearance
)设置为YES
. (YES
是默认值,因此您也可以将此值保留在plist之外 . )在viewDidLoad方法中,调用
[self setNeedsStatusBarAppearanceUpdate]
.实现
preferredStatusBarStyle
,返回此视图控制器所需的状态栏样式 .如果您的视图控制器位于独立的UINavigationController内,而不是基于故事板的UINavigationController的一部分,那么这里有一个问题,那么所有方法都失败了 . 我遇到了这种情况然后为了将状态栏设置为我使用的轻型样式
这对我很有用 .
在Swift中,我能够通过编写:
基本上你对最后一行很感兴趣 .
这导致tabbar变为白色:
请注意,我没有更改
Info.plist
中的任何内容以实现此结果 .有关更改
Navigation Status Bar
的更多信息,请查看此链接:http://www.appcoda.com/customize-navigation-status-bar-ios-7/我打赌你把你的视图控制器嵌入到导航控制器中 . 为避免将导航栏的样式设置为
.Black
,请使用此子类:Swift:
Objective C:
将此附加到
controller.m
文件viewDidLoad方法:然后在同一个
controller.m
文件中实现此方法:Official docs:
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TransitionGuide/Bars.html
Article I wrote on my blog:
http://www.ryadel.com/2015/03/04/xcode-set-status-bar-style-and-color-in-objective-c/
在ViewController中,您要更改状态栏的颜色
Swift扩展,因为我总是忘记这是如何工作的