我试图将我的应用程序标题文本颜色设置为白色,但是当我尝试设置titleTextAttributes似乎没有任何工作。
我有其他外观属性设置,如背景颜色和色调。但NSAttributedString.Key.foregroundColor似乎无法正常工作。我仔细检查文档,以确保它采取UIColor仍然似乎设置正确,没有结果。以下是我的AppDelegate供参考。
//Set the window as the visible view.
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
// Make the view controller default the homeController.
window?.rootViewController = UINavigationController(rootViewController: HomeController())
//Customise navBar appearance
let navBarAppearance = UINavigationBar.appearance()
navBarAppearance.isTranslucent = false
navBarAppearance.barTintColor = .backgroundLightBlack
navBarAppearance.tintColor = .seaFoamBlue
//This is the line that doesnt work :(
navBarAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
找到答案了!如果有人碰到这个。
我正在使用prefersLargeTitles = true导航栏。
为了设置此样式的标题文本属性,您需要LargeTitleTextAttributes,它设置与常规title属性完全相同,但使用largeTitleTextAttributes属性,例如:
navBarAppearance.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]