如何使用Color
而不是UIColor
作为导航栏文本?
例如,这项工作:
init() {
UINavigationBar.appearance().largeTitleTextAttributes = [
.foregroundColor: UIColor.red
]
}
这不是:
init() {
UINavigationBar.appearance().largeTitleTextAttributes = [
.foregroundColor: .red
]
}
我该如何正确地做到这一点?UIColor.red
比Color.red
丑得多
var largeTitleTextAttributes: [NSAttributedString.Key : Any]? { get set }
正如您所看到的,字典是[NSAttributedString.Key : Any]
,这意味着编译器无法推断.red
,这就是为什么您必须这样做,UIColor.red
。
.foregroundColor
工作得很好,因为它正在等待一个NSAttributedString.Key
。
在这种情况下,我恐怕不得不说你必须明确。
所以我刚刚发现UIColor.systemRed
和Color.red
是一样的。。。