J'ai fait la mise à jour de Xcode, pod de cacao, alamofire, alamofireimage aujourd'hui,Problème de texte à image rapide. Impossible de convertir la valeur de type '[String: Any]' en type d'argument attendu '[NSAttributedStringKey: Any]?'
maintenant j'ai une marque rouge sur mon code sur le texte à l'image. Je suis un débutant avec le codage.
func textToImage(drawText text: NSString, inImage image: UIImage, atPoint point: CGPoint) -> UIImage {
let textColor = UIColor.red
let textFont = UIFont(name: "Arial Rounded MT Bold", size: 24)!
let scale = UIScreen.main.scale
UIGraphicsBeginImageContextWithOptions(image.size, false, scale)
let textFontAttributes = [
NSAttributedStringKey.font.rawValue: textFont,
NSAttributedStringKey.foregroundColor: textColor,
] as! [String : Any]
image.draw(in: CGRect(origin: CGPoint.zero, size: image.size))
let rect = CGRect(origin: point, size: image.size)
text.draw(in: rect, withAttributes: textFontAttributes)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage!
}
la Comme marque rouge en ligne
text.draw(in: rect, withAttributes: textFontAttributes)
avec le message: Impossible de convertir la valeur de type '[Chaîne: Tous]' type d'argument attendu '[NSAttributedStringKey: Tout]?
changer votre type textFontAttributes à '[NSAttributedStringKey: Tous]' –
'laisser textFontAttributes: [NSAttributedStringKey: Tous] = [ .font: textFont, .foregroundColor: textColor]' –
Merci, il fonctionne à présent. 'Let textFontAttributes: [NSAttributedStringKey: Tous] = [ NSAttributedStringKey (rawValue: NSAttributedStringKey.font.rawValue): textFont, NSAttributedStringKey.foregroundColor: textColor, ]' – Geoff