Search code examples
cocoansviewnsbuttonnsrespondernsbuttoncell

NSButton: setting different focus ring color


I'm trying to set the NSButton focus ring color to white. Currently, when the button has firstResponder, it shows a blue outline.

I am aware that there is the drawFocusRingMaskWithFrame:inView: to help do this, but I'm not sure how to use this to change the color to white. I haven't seen any working examples of this API in use.

Thanks.


Solution

  • There's no way to do this. Your app has no direct control over the color of the focus ring. It only provides the shape (effectively a mask) and AppKit uses that to draw the focus ring.

    You can try to turn off the drawing of the focus ring for a particular view and then draw something intended to approximate a focus ring. However, this won't work well. The focus ring often extends beyond the frame of focused view, while the view's drawing can't.