Search code examples
swiftcocoanstextfieldnscolor

What is the system color of a NSTextField's text?


I manipulate the text color of a NSTextField. Due to the fact that these cells could be reused, I have to reset the color to the default one in my tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int)-Method.

How do I get via Swift source the default text color of a NSTextField-control?

I know that is should be black but I don't wanna 'guess' the color to be update, user interaction safe.

I looked for a NSTextField.defaultColor property or an NSColor.defaultTextFieldColor() but I did not find any helpful solutions. I also could not find anything related in the official Apple class reference.


Solution

  • If you're targeting 10.10 or later, then use NSColor.labelColor(). If you're targeting earlier versions of the OS, then use NSColor.controlTextColor().