2017-10-21 173 views
0

繪製透明文本我用下面的代碼畫上NSImage.How一個NSString我可以讓這個文本透明上NSImage中

text.draw(at: NSZeroPoint, withAttributes: [NSFontAttributeName: font, NSForegroundColorAttributeName: NSColor.white]) 

我怎樣才能讓這個文本透明?

請指點

回答

1

您可以使用NSColor方法withAlphaComponent(_:)並改變其顏色的不透明性。

text.draw(at: NSZeroPoint, 
      withAttributes: [NSFontAttributeName: font, 
          NSForegroundColorAttributeName: NSColor.white.withAlphaComponent(0.5)]) 
1

改變顏色的Alpha值,例如

text.draw(at: NSZeroPoint, withAttributes: [NSFontAttributeName: font, 
            NSForegroundColorAttributeName: NSColor(white: 1.0, alpha: 0.3)])