Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the effect of focusing on an NSTextField on OSX

In CSS, you can change the effect of focusing on something using:

.myelement:focus { ... }

While in Cocoa, the text fields always have an ugly blue glow. How do I change the effect of focusing on an NSTextField (or not have it do anything at all)?

like image 432
beakr Avatar asked Jun 07 '12 19:06

beakr


1 Answers

The Cocoa equivalent of the command above would be:

[[textField window] makeFirstResponder:textField];

As to changing the appearance, are you asking how to change it for all controls in all applications ("globally") or just for a text field in your own app? There's no API for a global change, so system hacks are your only avenue. Good luck.

For controls you own (those that belong to your own application), you can set the focus ring type in Interface Builder or by code at runtime like this:

[textField setFocusRingType:NSFocusRingTypeNone]; 
// (or NSFocusRingTypeDefault or NSFocusRingTypeExterior)
like image 190
Joshua Nozzi Avatar answered Sep 28 '22 02:09

Joshua Nozzi