Ios 更改标题的颜色
我已将上述代码放在AppDelegate文件中,标题的颜色仍然是黑色。您可以尝试以下操作:Ios 更改标题的颜色,ios,swift,uinavigationcontroller,Ios,Swift,Uinavigationcontroller,我已将上述代码放在AppDelegate文件中,标题的颜色仍然是黑色。您可以尝试以下操作: UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white] 试试这个 if #available(iOS 13.0, *) { let appearance = UINavigationBarAppe
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]
试试这个
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = .purple
appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().compactAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
} else {
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().barTintColor = .purple
UINavigationBar.appearance().isTranslucent = false
}
当我将Xcode更新到11.4时,出现了上述问题 突然,标题颜色变为黑色,之前是白色
let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.red]
UINavigationBar.appearance().titleTextAttributes = textAttributes
试一试:这能回答你的问题吗?
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = hexStringToUIColor(hex: "#7DB52F")
appearance.titleTextAttributes = [
NSAttributedString.Key.foregroundColor: UIColor.white
]
let buttonAppearance = UIBarButtonItemAppearance()
buttonAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.white]
appearance.buttonAppearance = buttonAppearance
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
UINavigationBar.appearance().compactAppearance = appearance
UIBarButtonItem.appearance().tintColor = UIColor.white
} else {
UINavigationBar.appearance().barTintColor = hexStringToUIColor(hex: "#7DB52F")
UINavigationBar.appearance().titleTextAttributes = [
NSAttributedString.Key.foregroundColor: UIColor.white
]
UINavigationBar.appearance().tintColor = UIColor.white
UIBarButtonItem.appearance().tintColor = UIColor.white
}