2017-10-21 42 views
0

J'utilise le code suivant dessiner une NSString sur un NSImage.How puis-je faire ce texte transparentDessiner le texte transparent sur NSImage

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

Comment puis-je faire de ce texte transparent?

S'il vous plaît conseiller

Répondre

1

Vous pouvez utiliser la méthode NSColor withAlphaComponent(_:) et modifier son opacité des couleurs.

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

Modifier la valeur alpha de la couleur, par exemple

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