tôi chuyển đổi ứng dụng của tôi thời gian gần đây và tôi vẫn gặp lỗiSwift lỗi 4 Chuyển đổi - NSAttributedStringKey: Bất kỳ
"Cannot convert value of type '[String : Any]' to expected argument type '[NSAttributedStringKey: Any]?'
barButtonItem.setTitleTextAttributes(attributes, for: .normal)
Tổng số các mã:
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
}
Tôi nhận được cảnh báo này. Có giải pháp nào không? Truyền từ '[NSAttributedStringKey: NSObject]' thành loại không liên quan '[String: Any]' luôn không thành công – Eazy
Cập nhật câu trả lời. Vui lòng kiểm tra –
Tôi đã sử dụng "let attributes = [NSAttributedStringKey.font: UIFont (tên:" Helvetica-Bold ", kích thước: 15.0) !, NSAttributedStringKey.foregroundColor: UIColor.trắng] "và tôi vẫn nhận được cảnh báo. – Eazy