UINavigationBar foregroundColor 使用 Color 而不是 UIColor

UINavigationBar foregroundColor use Color instead of 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 相同...