3
votes

When a editable NSTextField is selected Cocoa marks it as a default by making a blue rectangular around the text field.

But when editing ended the indicator can not be removed unless another text field has been selected.

To remove selection indicator what should we do ?

We are using following function to detect the editing's end.

 override func controlTextDidEndEditing(notification: NSNotification) {

   // doing things like getting the string user has been made.

   }
3
Even if I tried anotherTextField.becomeFirstResponder(), textField.resignFirstResponder nothing has been changed.Hope
Why not simply set the first responder of the window to nil which deselects the text field?vadian

3 Answers

5
votes

NSTextField by default draws Focus Ring to show active state. If you want to remove it, you can set t to none.

override func controlTextDidEndEditing(_ obj: Notification) {
    textField.focusRingType = .none
}

Note The NSTextField is still the first Responder, If user start typing again, the focus ring will not turn to blue. This is because you have programatically changed it. To get it back, you need to do it yourself.

4
votes

On your Xcode, select your Textfield -> Focus ring -> change from Default to None. enter image description here

1
votes

Try this

textField.window?.makeFirstResponder(self)