iOS 13 从 UINavigationController 中设置状态栏文本颜色 [英] iOS 13 Setting status bar text color from within UINavigationController

查看:22
本文介绍了iOS 13 从 UINavigationController 中设置状态栏文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以在 iOS 13 之前,我设置了 NavigationController.NavigationBar.BarStyle 来控制状态栏文本的颜色.但是现在有了新的 UINavigationBarAppearance,有没有办法控制它?我已经尝试覆盖preferedStatusBarStyle,并确保我的plist 也包含该设置,但据我所知,如果您的视图控制器位于 UINavigationController 内,这将不会受到尊重.

So before iOS 13, I was setting the NavigationController.NavigationBar.BarStyle to control the colour of the text int he status bar. But now witht he new UINavigationBarAppearance, is there anyway to control that? I've already tried overriding preferedStatusBarStyle, and ensured my plist contains the setting as well but as far as I can tell this isn't honored if your view controller sits inside a UINavigationController.

所以现在对于 iOS 13,我使用 UINavigationBarAppearance 设置导航栏的外观并设置 standardAppearance 和 scrollEdgeAppearance.

So now for iOS 13 I'm setting my navigation bar's appearance using the UINavigationBarAppearance and setting the standardAppearance and scrollEdgeAppearance.

我也在尝试将 NavigationController.NavigationBar.BarStyle 设置为 UIBarStyle.Black.它第一次工作,但由于某种原因,当我返回并再次导航到页面时,设置 BarStyle 不再有任何效果.

I'm also trying to set NavigationController.NavigationBar.BarStyle to UIBarStyle.Black. It works the first time, but for some reason when I go back and go navigate to the page again setting BarStyle no longer has any effect.

设置文本颜色的正确方法是什么?

What is the correct way to set the text color?

推荐答案

barStyle 在有限的条件下仍然有效.您可以使用 barStyle 或 UIBarAppearance 但不能同时使用两者,如果使用大标题,则不能使用 barStyle.

The barStyle does still work under limited conditions. You can use the barStyle or UIBarAppearance but not both, and you can’t use the barStyle if you use large titles.

当然,您可以通过继承 UINavigationController 来轻松解决问题.有点hacky,但很容易.

Of course you could trivially solve the problem just by subclassing UINavigationController. A bit hacky, but easy.

override var childForStatusBarStyle : UIViewController? {
    return self.topViewController
}

您在 iOS 13 中期望要做的是,不要理会状态栏样式,让它根据用户界面样式(浅色或深色模式)自动更改.在浅色模式下使用浅色条颜色,在深色模式下使用深色条形颜色,一切都会好起来的.

What you are expected to do in iOS 13, though, is leave the status bar style alone and let it change automatically in response to the user interface style (light or dark mode). Use a light bar color in light mode and a dark bar color in dark mode and all will be well.

这篇关于iOS 13 从 UINavigationController 中设置状态栏文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆