【问题标题】:Draw Transparent Text on NSImage在 NSImage 上绘制透明文本
【发布时间】:2018-04-02 06:09:27
【问题描述】:

我正在使用以下代码在 NSImage 上绘制 NSString。如何使此文本透明

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

如何使此文本透明?

请指教

【问题讨论】:

    标签: swift macos swift3 nsstring nsimage


    【解决方案1】:

    您可以使用 NSColor 方法withAlphaComponent(_:) 并更改其颜色不透明度。

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

    【讨论】:

      【解决方案2】:

      改变颜色的alpha值,例如

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

      【讨论】:

        猜你喜欢
        • 2020-08-17
        • 1970-01-01
        • 1970-01-01
        • 2012-12-02
        • 2021-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-20
        相关资源
        最近更新 更多