我最近转换了我的应用程序并且一直收到错误
"无法将'[String:Any]'类型的值转换为预期的参数类型'[NSAttributedStringKey:Any]?"
barButtonItem.setTitleTextAttributes(attributes, for: .normal)
整码:
class func getBarButtonItem(title:String) -> UIBarButtonItem {
let barButtonItem = UIBarButtonItem.init(title: title, style: .plain, target: nil, action: nil)
let attributes = [NSAttributedStringKey.font.rawValue: UIFont(name: "Helvetica-Bold", size: 15.0)!, NSAttributedStringKey.foregroundColor: UIColor.white] as! [String : Any]
barButtonItem.setTitleTextAttributes(attributes, for: .normal)
return barButtonItem
}
Run Code Online (Sandbox Code Playgroud) swift4 ×1