更改标题Swift的颜色

问题描述 投票:0回答:3
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]

我已将上面的代码放入AppDelegate文件中,标题的颜色仍然是黑色。

ios swift uinavigationcontroller
3个回答
1
投票
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 }

0
投票
let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.red] UINavigationBar.appearance().titleTextAttributes = textAttributes

0
投票
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 }
© www.soinside.com 2019 - 2024. All rights reserved.