【发布时间】:2019-01-15 21:22:43
【问题描述】:
我正在尝试将我的应用程序标题文本颜色设置为白色,但是当我尝试设置 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]
【问题讨论】:
-
您需要在创建导航控制器之前设置外观代理。或者直接设置你创建导航控制器的属性。
-
感谢 rmaddy,但这似乎没有奏效。我尝试在创建导航控制器之前直接进行设置,但都没有成功!还有什么建议吗?谢谢
标签: ios swift uinavigationbar appdelegate appearance