首页 > 解决方案 > 类型“NSAttributedStringKey”(又名“NSString”)没有成员“foregroundColor”

问题描述

以下是上述问题的代码行。此问题发生在Swift 4.1.

let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
navigationController?.navigationBar.titleTextAttributes = textAttributes

标签: iosnsattributedstringswift4.1nsattributedstringkey

解决方案


我通过替换属性字符串的键解决了这个问题。

这是我更新的代码是:

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

推荐阅读