![](/img/trans.png)
[英]UINavigationBar appearance + iOS 13 Dark Mode - How to set app wide color?
[英]How to set iOS 13 dark mode large title color?
在我的應用程序中,我使用
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 // saving in user defaults
中。 然后:
class PapaViewController: UIViewController {
if #available(iOS 13.0, *) {
overrideUserInterfaceStyle = Storage.isDarkModeOn ? .dark : .light
}
}
其中 PapaViewController 是我應用程序中所有 UIViewControllers 的父 class。 因此,如果overrideUserInterfaceStyle ==.dark
和設備顏色模式 == .light
出現錯誤。 如果然后我將設備顏色模式更改為.dark
,則大標題看起來符合預期。
您現在顯示的代碼的問題僅僅是您正在與錯誤的視圖 controller 交談。 您需要更改的不是您的視圖override
( self
):它是根視圖 controller,在這種情況下可能是導航 controller。
class PapaViewController: UIViewController {
if #available(iOS 13.0, *) {
self.navigationController?.overrideUserInterfaceStyle = // ...
}
}
你試過用iOS 13的新外觀API嗎?
https://developer.apple.com/documentation/uikit/uinavigationbarappearance
例子:
let style = UINavigationBarAppearance()
style.largeTitleTextAttributes = [.font: #YOURFONT#]
navigationController?.navigationBar.standardAppearance = style
navigationController?.navigationBar.scrollEdgeAppearance = ...
navigationController?.navigationBar.compactAppearance = ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.