按钮周围发光

发布于 2024-08-25 18:17:33 字数 79 浏览 3 评论 0原文

在 10.5 及更高版本中,如何在按钮或标签周围绘制轻微的白色“发光”?我已经看到一些应用程序可以做到这一点,但我仍然很困惑应该如何做到这一点。

How can I draw a slight white 'glow' around a button or label in 10.5 and later? I have seen some apps do it, but I am still confused how I should do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我做我的改变 2024-09-01 18:17:33

请参阅 NSShadow 。你会创建并设置阴影 (预先保存图形上下文),然后绘制按钮的基本形状,取消设置(通过恢复图形上下文) ,然后照常继续绘图。

对于像 NSButton 这样的现成控件,您将需要 子类化并覆盖其单元格绘图(并可能使主机 NSButton 控件本身更大一点,以容纳包含单元格“发光”所需的更大区域)。

可能可以通过设置标签的字体阴影来避免这种情况,但我认为IB不允许您这样做,因此您可以以编程方式为标签提供一个属性字符串(通过其 - setAttributedString:方法)。这些属性将包括 NSShadow(根据需要配置)作为 NShadowAttributeName。

See NSShadow. You'd create and set a shadow (saving your graphics context beforehand), then draw the basic shape of your button, unset it (by restoring your graphics context), then continue drawing as usual.

In the case of a ready-made control like NSButton, you will need to subclass and override its cell drawing (and possibly make the host NSButton control itself a bit larger to accommodate the larger area needed to encompass the "glow" of the cell).

You might be able to avoid this with a label by setting its font shadow, but I don't think IB lets you do this, so you'd programmatically give the label an attributed string (via its -setAttributedString: method). The attributes would include the NSShadow (configured as desired) as the NSShadowAttributeName.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文