在我的应用程序中我使用
let navigationBar = UINavigationBar.appearance()
navigationBar.largeTitleTextAttributes = [
NSAttributedString.Key.font: UIFont.SFProDisplay(ofSize: 34, weight: .bold),
NSAttributedString.Key.foregroundColor: UIColor.custom
]
static var custom: UIColor {
return UIColor(named: "color_custom")!
}
其中有一个颜色集 color_custom
。
但是在颜色模式之间切换时,它仅使用 Any Appearance 颜色。未使用深色外观。为什么?
添加:
经过一些研究后,我认为应该添加下一个问题:在我的应用程序中,我使用切换器在模式之间切换。
Storage.isDarkModeOn = newState//保存在用户默认值中
。然后:
class PapaViewController: UIViewController {
if #available(iOS 13.0, *) {
overrideUserInterfaceStyle = Storage.isDarkModeOn ? .dark : .light
}
}
PapaViewController 是我应用中所有 UIViewController 的父类。因此,如果 overrideUserInterfaceStyle == .dark
和设备颜色模式 == .light
错误就会出现。如果然后我将设备颜色模式更改为 .dark
,则大标题看起来符合预期。
最佳答案
您现在显示的代码的问题仅仅是您与错误的 View Controller 对话。您需要更改其覆盖
的不是您的 View Controller (self
):它是根 View Controller ,在本例中可能是导航 Controller 。
class PapaViewController: UIViewController {
if #available(iOS 13.0, *) {
self.navigationController?.overrideUserInterfaceStyle = // ...
}
}
关于ios - 如何设置iOS 13深色模式大标题颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58187167/