How to change the focus ring color?

眉间皱痕 提交于 2019-12-11 13:42:17

问题


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?

update: The 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.


回答1:


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.



来源:https://stackoverflow.com/questions/16057229/how-to-change-the-focus-ring-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!