2017-07-30 3 views
-1

Le compilateur continue de lancer cette erreur: "Le type d'expression est ambigu sans plus de contexte". Il le lance sur: let textFontAttributes = [NSAttributedString. Quelqu'un peut-il m'indiquer la bonne direction. Merci.Xcode Swift - Le texte attribué ne fonctionnera pas avec les attributs de police

let textRect = CGRect(x: 50, y: 60, width: 56, height: 35) 
    let textTextContent = String(globalWorkoutCount) + "/7" 
    let textStyle = NSMutableParagraphStyle() 
    textStyle.alignment = .center 
    let textFontAttributes = [NSAttributedString: UIFont(name: "Avenir-Medium", size: 24)!, NSForegroundColorAttributeName: UIColor.white, NSMutableParagraphStyle: textStyle] 

    let textTextHeight: CGFloat = textTextContent.boundingRect(with: CGSize(width: textRect.width, height: CGFloat.infinity), options: .usesLineFragmentOrigin, attributes: textFontAttributes, context: nil).height 
    context.saveGState() 
    context.clip(to: textRect) 
    textTextContent.draw(in: CGRect(x: textRect.minX, y: textRect.minY + (textRect.height - textTextHeight)/2, width: textRect.width, height: textTextHeight), withAttributes: textFontAttributes) 
    context.restoreGState() 

Répondre

1

changement NSAttributedString à NSFontAttributeName et NSMutableParagraphStyle à NSParagraphStyleAttributeName et cela devrait fonctionner.

Voici ce qu'elle devrait finir par ressembler à:

let textFontAttributes = [NSFontAttributeName: UIFont(name: "Avenir-Medium", size: 24)!, NSForegroundColorAttributeName: UIColor.white, NSParagraphStyleAttributeName: textStyle]