在 swift 4 - NSAttributedString 表示完全改变。
替换你的属性字典 -attributes类型,从[String : Any]到[NSAttributedStringKey : Any] 或[NSAttributedString.Key : Any],如果你还没有完成。
试试这个
斯威夫特 4.2+:
attributes[NSAttributedString.Key.font] = font
attributes[NSAttributedString.Key.foregroundColor] = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1)
斯威夫特 4.0 和 4.1:
attributes[NSAttributedStringKey.font] = font
attributes[NSAttributedStringKey.foregroundColor] = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1)
这是来自 Apple 文档的注释:NSAttributedString.Key