上NSImage中
问题描述:
绘制透明文本我用下面的代码画上NSImage.How一个NSString我可以让这个文本透明上NSImage中
text.draw(at: NSZeroPoint, withAttributes: [NSFontAttributeName: font, NSForegroundColorAttributeName: NSColor.white])
我怎样才能让这个文本透明?
请指点
答
您可以使用NSColor方法withAlphaComponent(_:)并改变其颜色的不透明性。
text.draw(at: NSZeroPoint,
withAttributes: [NSFontAttributeName: font,
NSForegroundColorAttributeName: NSColor.white.withAlphaComponent(0.5)])
答
改变颜色的Alpha值,例如
text.draw(at: NSZeroPoint, withAttributes: [NSFontAttributeName: font,
NSForegroundColorAttributeName: NSColor(white: 1.0, alpha: 0.3)])