2017-07-30 23 views
-1

コンパイラはこのエラーをスローし続けます。「式の種類はコンテキストがなくてもあいまいです。それはそれを投げている:let textFontAttributes = [NSAttributedString。誰かが私を正しい方向に向けることができますか?ありがとう。 NSParagraphStyleAttributeNameXcode Swift - 属性属性はフォント属性では機能しません

NSFontAttributeNameNSMutableParagraphStyle
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() 

答えて

1

変更NSAttributedString、それが動作するはずです。

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

は、それがのように見える終わるべきものです

関連する問題