小编Eaz*_*azy的帖子

Swift 4转换错误 - NSAttributedStringKey:Any

我最近转换了我的应用程序并且一直收到错误

"无法将'[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

29
推荐指数
3
解决办法
3万
查看次数

标签 统计

swift4 ×1