swift - 如何指定各个导航栏的标题颜色? swift

标签 swift colors navigation

假设我有 3 个 View Controller ,A、B 和 C。

A 为黑色背景,B 为白色,C 为蓝色。

所有这些都使用 NavigationControllerBars 进行导航。

如何以编程方式更改导航栏标题的颜色?

这样我在 A 上有一个白色标题,B 上有黑色标题,C 上可能有红色标题。

根据我收集的信息,每个人都使用例如:

navigationController?.navigationBar.titleTextAttributes = [NSForegroundAttributeName: UIColor.white]

我是 swift 新手,但对我来说它看起来像 Obj-C?

这对我不起作用,而且我不断得到

Replace 'NSForegroundColorAttributeName' with 'NSForegroundColorAttributeName.rawValue'

作为一个错误。

最佳答案

我在代码中使用了它,并且编译没有任何问题。

swift 2.3

navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]

swift 3

navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]

关于swift - 如何指定各个导航栏的标题颜色? swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45411069/

相关文章:

graphics - 了解颜色

javascript - 浏览长的无序列表

ios - Swift : Main. Storyboard本地化失败

ios - 根据滚动逐渐改变背景颜色

Java:更好的颜色选择算法

Android ViewPager 上一个/下一个按钮

reactjs - Expo 相机仅通过 React Navigation 打开一次

swift - Xcode GM : no swift language for OS X command line tool project?

ios - 如何在按下 searchBar 时显示 UISearchController 的 searchResultsController

ios7 - 我用 Swift 实现的 NSXMLParser 适用于 iOS 8,但不适用于 7.1