I have a NSTextField
which has the background colour set as clear.
When I press enter, the textfield goes into editing mode and starts renaming the file just as Xcode
.
Here I want to change the background colour to white. Currently, I am changing the background colour in controlTextDidBeginEditing(_ obj: Notification)
which is called after the textfield receives a change in text.
However, I am looking for a method which can change the background colour as soon as I press enter.
Here is my current code:
private class TextField: NSTextField, NSTextFieldDelegate {
init() {
super.init(frame: .zero)
delegate = self
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public func controlTextDidBeginEditing(_ obj: Notification) {
let textField = obj.object as! NSTextField
textField.backgroundColor = NSColor.textBackgroundColor
}
public func controlTextDidEndEditing(_ obj: Notification) {
let textField = obj.object as! NSTextField
textField.backgroundColor = NSColor.clear
}
}
Thanks.