Swift - Drawing text with drawInRect:withAttributes:

前端 未结 5 619
自闭症患者
自闭症患者 2020-12-14 08:15

I have strange problem with Xcode 6.1 GM.

let text: NSString = \"A\"
let font = NSFont(name: \"Helvetica Bold\", size: 14.0)

let textRect: NSRect = NSMakeRe         


        
5条回答
  •  甜味超标
    2020-12-14 09:07

    In XCode 12, Swift 5.3. i was not able to find the draw method for String object. After i manually cast to NSString, it worked for me.

    let text: String = "XXX"
    (text as NSString).draw(in: rect withAttributes: attributes)
    

提交回复
热议问题