UINavigationBar foregroundColor使用Color而不是UIColor



如何使用Color而不是UIColor作为导航栏文本?

例如,这项工作:

init() {
UINavigationBar.appearance().largeTitleTextAttributes = [
.foregroundColor: UIColor.red
]
}

这不是:

init() {
UINavigationBar.appearance().largeTitleTextAttributes = [
.foregroundColor: .red
]
}

我该如何正确地做到这一点?UIColor.redColor.red丑得多

var largeTitleTextAttributes: [NSAttributedString.Key : Any]? { get set }

正如您所看到的,字典是[NSAttributedString.Key : Any],这意味着编译器无法推断.red,这就是为什么您必须这样做,UIColor.red

.foregroundColor工作得很好,因为它正在等待一个NSAttributedString.Key

在这种情况下,我恐怕不得不说你必须明确。

所以我刚刚发现UIColor.systemRedColor.red是一样的。。。

最新更新