Using NSTextField I'd like to change the text color from black to white when going into edit mode.
Right now, it:
- Defaults to black when not selected (GOOD)
- Defaults to white when selected (GOOD)
- Changes color to black when editing starts (NOT GOOD), would like for it to be white.
I know I could set the textColor property to .white but that would also set the color to white when the row is not selected (see point 1.), which I don't want. Huge thanks in advance!
Code I'm using now for reference, note is part of a NSViewRepresentable struct.
func makeNSView(context:Context) -> NSTextField{
    let osTextView = NSTextField(string: inputText)
    osTextView.maximumNumberOfLines = 1
    osTextView.isBordered = false
    osTextView.delegate = context.coordinator
    osTextView.drawsBackground = true
    osTextView.backgroundColor = .none
    //osTextView.textColor = .white
    
    return osTextView
}
I've tried adding the following and it almost gets the job done, however it only triggers when edit begins as opposed to when NSTextField becomes editable.
func control(_ control: NSControl, textShouldBeginEditing fieldEditor: NSText) -> Bool {
        fieldEditor.textColor = .white
        return true
    }




 
                        
So the way I managed to solve it is by subclassing NSTextField and overriding becomeFirstResponder. As that only triggers when the field goes into edit mode I can set there the color to white.
Once the user finishes I reset the color at
You may wonder why I don't reset it at resignsFirstResponder, the reason is this (TLDR -> would not work).
And here is the end result: