我的应用程序背景是黑色的,但在iOS 7中,状态栏变成了透明的。所以我什么也看不见,只有角落里的绿色电池指示灯。如何将状态栏文本颜色改为白色,就像在主屏幕上一样?
当前回答
如果你的UIViewController在UINavigationController中,你必须设置BarStyle:
-[UINavigationBar setBarStyle:UIBarStyleBlack]
原始答案在这里
https://devforums.apple.com/message/844264#844264
其他回答
简单地调用
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
在
-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
}
我的AppDelegate的方法在iOS7中非常适合我。
这个答案是在hackingwithswift网站的帮助下得出的
用于iOS (13, *)
有时候我们需要不同颜色的状态栏,例如对于一个ViewController我们需要黑色的状态栏,而对于第二个ViewController我们需要白色的状态栏。 现在我们要做什么? 我们需要在ViewController中添加这个和平代码
// MARK: - Variables
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
// MARK: - View Life Cycle
override func viewDidAppear(_ animated: Bool) {
setNeedsStatusBarAppearanceUpdate()
}
这段代码将改变特定ViewController中状态栏的浅色或白色。我们可以在preferredStatusBarStyle中将其更改为。dark
欲了解更多细节,请访问hackingwithswift
这适用于Golden Master iOS7和Xcode 5 GM种子和2013年9月18日发布的iOS7 SDK(至少导航控制器隐藏):
中的UIViewControllerBasedStatusBarAppearance设置为NO Info.plist。 在ViewDidLoad方法或任何地方,你想改变的地方 状态栏样式: [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
在Swift 5的例子中,我添加了这些行:
override func viewDidAppear(_ animated: Bool) {
navigationController?.navigationBar.barStyle = .black
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
这对我来说真是小菜一碟。
去你的应用的info.plist。
“查看基于控制器的状态栏外观”设置为“否” 设置状态栏样式为UIStatusBarStyleLightContent
然后转到你的应用程序的委托,并粘贴下面的代码,你设置你的窗口的RootViewController。
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,320, 20)];
view.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
[self.window.rootViewController.view addSubview:view];
}
宾果。这对我很有用。
推荐文章
- 如何删除默认的导航栏空间在SwiftUI导航视图
- Ios模拟器:如何关闭应用程序
- 如何在iOS中使用Swift编程segue
- Swift -整数转换为小时/分钟/秒
- 如何舍入一个双到最近的Int在迅速?
- 扁平化数组的数组在Swift
- Swift:声明一个空字典
- 在成功提交我的应用程序后,“太多符号文件”
- 从数组中随机选择一个元素
- 首先添加一个UIView,甚至是导航栏
- 我如何改变UIButton标题颜色?
- 在Swift中如何调用GCD主线程上的参数方法?
- NSLayoutConstraints是可动画的吗?
- iOS -构建失败,CocoaPods无法找到头文件
- CFNetwork SSLHandshake iOS 9失败