Search code examples
swiftcocoanstextfield

Change color of NSTextField


I'm trying to code an easy example to modify the color of a NSTextfield playing with green and red colors as good answer or wrong. I cannot achieve that cause i always obtained an error message when using this apple guide page for NSTextField, AppKit framework ref.

I'm trying to use this code :

@IBOutlet weak var mensajeResultado: NSTextField! 

when trying to colorize it without success
let rango = NSRange(location: 0,length: 0)
        mensajeResultado.superclass.setTextColor(NSColor.redColor(), range: rango)

Solution

  • Shouldn't it just be:

    mensajeResultado.textColor = NSColor.redColor()
    

    ?