简体   繁体   English

如何在 MoreTabBarController 中将 UIStatusBar 颜色更改为 .lightContent

[英]How do I change the UIStatusBar color to .lightContent in the MoreTabBarController

I have a UITabBarController with more than 5 UIViewControllers .我有一个超过 5 个UIViewControllersUITabBarController I have set the value in my info.plist I have set the value for ViewController based status bar appearance to YES .我已经在我的info.plist中设置了值 我已经将基于ViewController的状态栏外观的值设置为YES

在此处输入图像描述

All of the UIViewControllers have the values所有的 UIViewControllers 都有值

UIApplication.shared.statusBarUIView?.backgroundColor = customColor
self.setNeedsStatusBarAppearanceUpdate()

in viewDidLoad with customColor being a dark shade of blue.在 viewDidLoad 中,customColor 是深蓝色。 I'm also overriding the preferredStatusBarStyle variable to light content.我还覆盖了preferredStatusBarStyle 变量以显示内容。

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

All UIViewControllers display the lightContent status bar.所有 UIViewController 都显示 lightContent 状态栏。 I have tried the same in the MoreTabBarController class but it doesn't work.我在 MoreTabBarController class 中尝试过相同的方法,但它不起作用。 I'm assuming the reason is because it isn't a UIViewController but rather a UITabBarController.我假设原因是因为它不是 UIViewController 而是 UITabBarController。

在此处输入图像描述

How do I change the Status bar color to light content in the MoreTabBarController?如何将状态栏颜色更改为 MoreTabBarController 中的浅色内容?

Use UIApplication.shared.statusBarStyle =.lightContent in didFinishLaunchingWithOptions and then use View controller-based status bar appearance key and set No for its boolean value in.info plist.在 didFinishLaunchingWithOptions 中使用UIApplication.shared.statusBarStyle =.lightContent ,然后在.info plist 中使用View controller-based status bar appearance键并将其 boolean 值设置为 No。 Its change Status bar color to light content.它将状态栏颜色更改为浅色内容。

Open project settings option you can change status bar's style:打开项目设置选项,您可以更改状态栏的样式:

在此处输入图像描述

Next, go back to the Storyboard, Select the ViewController and in the Editor menu Select Embedin NavigationController .接下来,go 回到 Storyboard,Select ViewController和编辑器菜单 ZE062621 NavigationController Select the Navigation Bar and in the Attribute Inspector set the Bar Tint color to red. Select 导航栏并在属性检查器中将 Bar Tint 颜色设置为红色。 Build and Run the project, The content of the status bar is dark again, which is the default.构建并运行项目,状态栏的内容又变暗了,这是默认的。 The reason for this is, iOS asked for the style of the status bar of the navigation controller instead of the contained ViewController .原因是,iOS 要求导航状态栏的样式 controller 而不是包含的ViewController To change the style of all navigation controller inside the app, change the following method in the AppDelegate.swift file.要更改应用内所有导航controller的样式,请在AppDelegate.swift文件中更改以下方法。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    UINavigationBar.appearance().barStyle = .blackOpaque
    return true
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM