In the draw function of the
NSImageView,I want to set my custom focus ring color,not the default blue color.I tried as follows code
NSSetFocusRingStyle(NSFocusRingOnly); [[NSColor redColor] setStroke]; NSRectFill([self bounds]);
But the color is still default blue color.How can I solve this problem?
NSShadow class help me to accomplish adding focus ring.It's easy to change the shadow color.
NSShadow *shadow = [[[NSShadow alloc] init] autorelease]; [shadow setShadowBlurRadius:5]; [shadow setShadowOffset:NSMakeSize(0.0, 0.0)]; [shadow setShadowColor:[NSColor redColor]]; [shadow set];
I code this in the NSImageView's draw function.Answer1:
The only way to solve this "problem" is to draw the focus ring yourself. The
NSFocusRingStyle code is designed to make it easy for you to draw a focus ring in the user's selected focus style, which includes them being able to set the focus ring color.
It is by design that you cannot easily change the focus ring color, as it is part of the OS theme and thus should be under the user's control (according to the HIG). If you have a special case, such as needing to adaptively color the focus ring based on the contents of the image, you will have to create your own focus ring from scratch.