FocusRing color change for NSTextField, NSTextView

How to change focusRing color from blue to red.

(This question is continued with a General input check , instead of setting the default blue focus, I need red.)

The default value is as follows:

enter image description here

I need something like this (Note: the image shown is not perfect, as shown inside the box):

enter image description here

I have tried several things from

but without success.

Your help is needed.

+4
source share
1 answer

subclass NSTextview and paste below code

-(void)mouseEntered:(NSEvent *)theEvent{ CALayer *lay = [self layer]; CGColorRef myColor=CGColorCreateGenericRGB(0, 0, 1, 1); [lay setBorderColor:myColor]; [lay setBorderWidth:4]; //[self setWantsLayer:YES]; [self setLayer:lay]; [self makeBackingLayer]; //CGColorRelease(myColor); } -(void)mouseExited:(NSEvent *)theEvent{ CALayer *lay = [self layer]; CGColorRef myColor=CGColorCreateGenericRGB(0, 0, 1, 1); [lay setBorderColor:myColor]; [lay setBorderWidth:0]; //[self setWantsLayer:YES]; [self setLayer:lay]; [self makeBackingLayer]; //CGColorRelease(myColor); } -(void)updateTrackingAreas{ [super updateTrackingAreas]; if (trackingArea){ [self removeTrackingArea:trackingArea]; [trackingArea release]; } NSTrackingAreaOptions options = NSTrackingInVisibleRect | NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow; trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:options owner:self userInfo:nil]; [self addTrackingArea:trackingArea]; } 
+1
source

Source: https://habr.com/ru/post/1480243/


All Articles