我的应用程序背景是黑色的,但在iOS 7中,状态栏变成了透明的。所以我什么也看不见,只有角落里的绿色电池指示灯。如何将状态栏文本颜色改为白色,就像在主屏幕上一样?
当前回答
让我来完整地回答你的问题。改变状态栏文本的颜色非常简单,但是在ios7中对新手来说有点混乱。
如果你试图通过选择视图控制器并在右侧选择模拟度量来将Storyboard中的颜色从黑色改为白色,它不会工作,我不知道为什么。它应该通过这样的改变来工作,但无论如何。
其次,你不会在你的plist中找到UIViewControllerBasedStatusBarAppearance属性,但默认情况下它不在那里。你必须自己添加它,点击+按钮,然后设置为NO。
ios7状态栏的文本颜色
最后,你需要到AppDelegate。然后在didFinishLaunchingWithOptions方法中添加如下内容,添加如下一行:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
这将改变所有视图控制器的颜色为白色。希望这能有所帮助!
其他回答
注:最高赞数的答案不适用于iOS 7 / 8
在信息。plist设置“视图基于控制器的状态栏外观”为NO
在AppDelegate中添加
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
to
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
...
}
此解决方案适用于iOS 7 / 8。
Xcode GM Seed的答案更新:
在信息。plist将基于视图控制器的状态栏外观设置为NO 在项目中,设置: 在ViewDidLoad: [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
非常简单的方法来改变状态栏的颜色。 创建navigation Controller的子类。
在view didload方法中编写以下代码。 在所有视图控制器中执行此代码
self.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName :
[UIColor whiteColor],
NSFontAttributeName:[UIFont boldSystemFontOfSize:19]};
对我来说,什么都没用。我试图改变状态栏颜色在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.
如果你有一个通过Interface Builder创建的嵌入式导航控制器,请确保在管理导航控制器的类中设置以下内容:
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
这应该就是你所需要的。
推荐文章
- 我应该如何从字符串中删除所有的前导空格?- - - - - -斯威夫特
- 如何使用Xcode创建。ipa文件?
- 动态改变UILabel的字体大小
- 在iPhone上确定用户是否启用了推送通知
- 是否有可能禁用浮动头在UITableView与UITableViewStylePlain?
- Swift:理解// MARK
- 错误ITMS-9000:“冗余二进制文件上传。火车1.0版本已经有一个二进制版本上传。
- Swift -转换为绝对值
- Swift编译器错误:“框架模块内的非模块化头”
- 从父iOS访问容器视图控制器
- 自定义dealloc和ARC (Objective-C)
- 调整UITableView的大小以适应内容
- 在代码中为UIButton设置一个图像
- NSRange从Swift Range?
- 我可以使用范围操作符与if语句在Swift?