iOS: 不使用 UINavigationController 设置状态栏颜色
iOS: setting statusbar color without using UINavigationController
在我的 iOS 应用程序中,我使用的是 没有 UINavigationController 的 UINavigationBar。我怎样才能设置应用程序状态栏的颜色以匹配我的 UINavigationBar 的颜色,这是一种自定义的蓝色?已尝试但无效:
- 在 plist 中设置
UIViewControllerBasedStatusBarAppearance
属性 没有任何效果
- 设置我的 UINavigationBar 的
barTintColor
不会影响状态栏,大概是因为它不是由 UINavigationViewController 管理的吧?
- 设置
UINavigationBar.appearance().barTintColor
也不行
有什么建议吗?
将此方法添加到您的视图控制器:
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent; // or UIStatusBarStyleDefault
}
好的,多亏了这个问题的公认答案,我才弄明白了:
How to add custom navigation bar to a full-screen VC in iOS 7 and make it tint the status bar to match?
在您的 viewcontroller 中采用 UINavigationBarDelegate 协议并实现以下方法 (Swift):
func positionForBar(bar: UIBarPositioning) -> UIBarPosition {
return UIBarPosition.TopAttached
}
显然,以这种方式定位的所有导航栏都将其 barTintColor 扩展到状态栏。
在我的 iOS 应用程序中,我使用的是 没有 UINavigationController 的 UINavigationBar。我怎样才能设置应用程序状态栏的颜色以匹配我的 UINavigationBar 的颜色,这是一种自定义的蓝色?已尝试但无效:
- 在 plist 中设置
UIViewControllerBasedStatusBarAppearance
属性 没有任何效果 - 设置我的 UINavigationBar 的
barTintColor
不会影响状态栏,大概是因为它不是由 UINavigationViewController 管理的吧? - 设置
UINavigationBar.appearance().barTintColor
也不行
有什么建议吗?
将此方法添加到您的视图控制器:
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent; // or UIStatusBarStyleDefault
}
好的,多亏了这个问题的公认答案,我才弄明白了: How to add custom navigation bar to a full-screen VC in iOS 7 and make it tint the status bar to match?
在您的 viewcontroller 中采用 UINavigationBarDelegate 协议并实现以下方法 (Swift):
func positionForBar(bar: UIBarPositioning) -> UIBarPosition {
return UIBarPosition.TopAttached
}
显然,以这种方式定位的所有导航栏都将其 barTintColor 扩展到状态栏。