我的应用程序背景是黑色的,但在iOS 7中,状态栏变成了透明的。所以我什么也看不见,只有角落里的绿色电池指示灯。如何将状态栏文本颜色改为白色,就像在主屏幕上一样?
当前回答
在iOS 8中: add NavigationController.NavigationBar.BarStyle = UIBarStyle.Black;对viewDidLoad
其他回答
在信息。plist设置“视图基于控制器的状态栏外观”为NO
在AppDelegate中添加
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
或者,你可以选择退出基于视图控制器的状态栏外观:
在Info.plist中设置“基于视图控制器的状态栏外观”为“NO”。 调用[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
注意:此方法在iOS9中已弃用。在UIViewController上使用preferredStatusBarStyle代替。(见苹果开发者库)
这招对我很管用:
在plist中设置UIViewControllerBasedStatusBarAppearance为YES rootViewController需要方法实现 ——(UIStatusBarStyle) preferredStatusBarStyle
因为我的rootViewController是由Cocoapods (JASidePanelController)管理的,我通过一个类别添加了这个方法:
#import "JASidePanelController+StatusBarStyle.h"
@implementation JASidePanelController (StatusBarStyle)
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
@end
对我来说,什么都没用。我试图改变状态栏颜色在ViewController2,这是嵌入在NavigationController,这反过来,从ViewController1被模态地呈现。这种方法行不通:
override var preferredStatusBarStyle: UIStatusBarStyle {
return .darkContent
}
什么都没有发生,直到我找到了这个解决方案: 将这一行添加到ViewController1
导航控制器。modalPresentationCapturesStatusBarAppearance = 真正的
let navigationController = UINavigationController(rootViewController: viewController2)
navigationController.modalPresentationStyle = .overFullScreen
navigationController.modalTransitionStyle = .crossDissolve
navigationController.modalPresentationCapturesStatusBarAppearance = true
self.present(navigationController, animated: true)
所以如果你的导航方案类似于ViewController1呈现的ViewController2,尝试modalPresentationCapturesStatusBarAppearance属性呈现的一个
文档:
The default value of this property is false. When you present a view controller by calling the present(_:animated:completion:) method, status bar appearance control is transferred from the presenting to the presented view controller only if the presented controller's modalPresentationStyle value is UIModalPresentationStyle.fullScreen. By setting this property to true, you specify the presented view controller controls status bar appearance, even though presented non-fullscreen. The system ignores this property’s value for a view controller presented fullscreen.
你可以在iOS 6和7中使用这个:
#ifdef __IPHONE_7_0
# define STATUS_STYLE UIStatusBarStyleLightContent
#else
# define STATUS_STYLE UIStatusBarStyleBlackTranslucent
#endif
[[UIApplication sharedApplication] setStatusBarStyle:STATUS_STYLE animated:YES];
推荐文章
- CFNetwork SSLHandshake iOS 9失败
- swift语言中的结构与类
- 我如何在Swift连接字符串?
- 请求失败:不可接受的内容类型:文本/html使用AFNetworking 2.0
- 缺少推荐的图标文件-该包不包含iPhone / iPod Touch的应用程序图标,像素为“120x120”,png格式
- 以编程方式创建segue
- 我应该如何从字符串中删除所有的前导空格?- - - - - -斯威夫特
- 如何使用Xcode创建。ipa文件?
- 动态改变UILabel的字体大小
- 在iPhone上确定用户是否启用了推送通知
- 是否有可能禁用浮动头在UITableView与UITableViewStylePlain?
- Swift:理解// MARK
- 错误ITMS-9000:“冗余二进制文件上传。火车1.0版本已经有一个二进制版本上传。
- Swift -转换为绝对值
- Swift编译器错误:“框架模块内的非模块化头”