如何改变对焦环的颜色? [英] How to change the focus ring color?

查看:197
本文介绍了如何改变对焦环的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSImageView 的绘图函数中,我想设置自定义的对焦环的颜色,而不是默认的蓝色。我试过如下代码:

  NSSetFocusRingStyle(NSFocusRingOnly); 
[[NSColor redColor] setStroke];
NSRectFill([self bounds]);



但是颜色仍然是默认的蓝色。我怎样才能解决这个问题?



更新:
NSShadow 类帮助我完成添加聚焦环。改变阴影颜色很容易。 p>

  NSShadow * shadow = [[[NSShadow alloc] init] autorelease]; 
[shadow setShadowBlurRadius:5];
[shadow setShadowOffset:NSMakeSize(0.0,0.0)];
[shadow setShadowColor:[NSColor redColor]];
[shadow set];

我在NSImageView的draw函数中编写了这个代码。

解决这个问题的唯一方法是自己绘制焦点环。 NSFocusRingStyle 代码旨在使您可以轻松地在用户所选的对焦样式中绘制对焦环,其中包括可以设置对焦环的颜色。

在设计上,由于它是操作系统主题的一部分,所以不能轻易改变对焦环的颜色,因此应该由用户控制(根据HIG )。如果您有特殊情况,例如需要根据图像的内容自适应地调整对焦环的颜色,则必须从头创建自己的对焦环。


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.

解决方案

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.

这篇关于如何改变对焦环的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆