2017-10-21 7 views
0

ich den folgenden Code bin mit kann ein NSString auf einem NSImage.How Draw mache ich diesen Text transparentauf NSImage Transparent Text Zeichnen

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

Wie kann ich diesen Text transparent machen?

Bitte Rat

Antwort

1

Sie NSColor Methode withAlphaComponent(_:) und ändern ihre Farbe Opazität verwenden können.

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

Ändern Sie den Alpha-Wert der Farbe, zum Beispiel

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