2017-10-21 99 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)])