问题标签 [nsbuttoncell]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
992 浏览

macos - NSButton在drawRect中着色图像

我想在 drawRect 中为我的按钮着色,但找不到正确的设置来为图像着色

- 按钮是无边框的,带有灰度图像,我想着色

在我的 NSButton 子类中:

0 投票
0 回答
230 浏览

objective-c - Custom NSButtonCell rendering and default buttons

I've recently come across a problem with a custom NSButtonCell subclass. We have a dark interface with white text, and all is going as expected, until we try to make a default button (i.e. assigning a key equivalent of \r). What we get seems mysterious: The bezel draws, but the text doesn't. But if I make the text black, it draws. If I make the text white with a black shadow, only the shadow draws!

The mystery started to unravel when I tried a test with the text set to [NSColor redColor] on a lark. (The "Create" button here has a key equivalent of \r, "Cancel" is Esc.)

red button test

What I eventually figured out is that the default button's cell is drawing into a bitmap context, presumably so that the rendered glyphs can be cached for the animated blue pulsing background that the Aqua look gives. That makes total sense, but the surprise is that that bitmap is then drawn with a multiply compositing operation. Hence black shows up and white doesn't, and anything in between shows up darkened.

I've managed to hack a workaround, by taking the text rendering out of -drawTitle:withFrame:inView: and doing it in -drawBezelInFrame:inView: instead. But that gets called repeatedly, so I'll need to manually cache the image. Plus it's just conceptually ugly, because it's specifically the wrong method for rendering the title!

My question: Surely there must be a better way, right? Is there some way to tell the button cell not to automatically use this offscreen rendering path even though the button is default?

0 投票
1 回答
202 浏览

cocoa - 取消选中绑定 NSTableview 列内的复选框时出现问题

我正在使用由aneesh171创建的这个项目,它显示了在 NSTableView 中创建复选框以及如何绑定它们。我是 OSX 开发的新手,并试图了解它是如何工作的。

该项目基本上是绑定到数组控制器的 NSTableView 列内的复选框。

出于某种原因,当我取消选择其中一个复选框时,控制台窗口上会出现以下消息:

选中该复选框后,此消息不会显示在控制台上。

你们能告诉我有什么问题吗?

0 投票
1 回答
1217 浏览

objective-c - NSButton 子类更改按钮图像

我进行了子类NSButton化,以便单击按钮图像时会发生变化。以下代码用于子类。

这是当前按钮。正如你所看到的,按钮在被点击后并没有返回到它的原始图像,mouseUp事件。

在此处输入图像描述

关于为什么在活动期间图像没有恢复到原始状态的任何想法mouseUp

0 投票
0 回答
101 浏览

macos - 检查 Mac App Store 拒绝的私有类名称理由?

我注意到“股票”Aqua 单选按钮和复选框图像是使用正常NSButtonCell方法绘制的,-drawImage:withFrame:inView:.

在我的NSButtonCell子类中绘图时,我想区分正在传递的库存图像和开发人员提供的图像。如果图像是自定义图像,我希望使用它,但如果它是默认界面图像,我想自己处理绘图。那有意义吗?

无论如何,我已经编写了一个方法来检查图像是否是默认界面图像,它看起来像这样:

由于 Apple 提供的图像使用私有类,因此我使用该NSClassFromString()函数在运行时为我输出它,因此我不会收到一堆编译器警告。这种技术效果很好,有了它,我可以确定是否应该绘制传递给绘图方法的图像。问题是,我不希望仅仅因为我引用了一个私有类而开发人员的应用程序不被 Mac App Store 接受。

我对这一切都不熟悉,所以我不确定苹果的规则有多“严格”。如果有人知道 Apple 在使用私有类或框架的名称方面的界限,我很想知道。谢谢!

0 投票
1 回答
722 浏览

cocoa - NSButton:设置不同的对焦环颜色

我正在尝试将 NSButton 焦点环颜色设置为白色。目前,当按钮有 firstResponder 时,它显示一个蓝色轮廓。

我知道有drawFocusRingMaskWithFrame:inView:来帮助做到这一点,但我不知道如何使用它来将颜色更改为白色。我还没有看到使用此 API 的任何工作示例。

谢谢。

0 投票
0 回答
459 浏览

objective-c - 我的 NSButtonCell 发生了哪些秘密事情?

我正在编写一个 OS X 应用程序(目标 10.10,Xcode 6.1),我对我的自定义 NSButtonCell 子类感到非常困惑。似乎这里发生了不应该发生的事情。我是 OS X 编程的新手,所以我问是否有人深入了解 NSButtonCell 的内部工作原理。

首先,什么似乎有效?

  1. 我可以设置按钮的图像和标题。图像正常显示。
  2. 故事板将按钮设置为 Style: Textured 和 Type: Momentary Change。它不是有边界的,不是透明的,也不允许混合状态。

投诉清单:

  1. 我重写-drawTitle:withFrame:inView:以根据单元格的自定义颜色绘制标题highlighted。这种颜色应该#cccccc单元格未突出显示时的颜色,但实际上是#d6d6d6.
  2. 该按钮具有图像和备用图像。绘制的图像永远不是备用图像,因此我覆盖-drawImage:withFrame:inView:为单元格的highlighted. 这似乎可行,但到底是什么,NSButtonCell?开/关状态与突出显示有何不同?highlighted我已经尝试了许多类型选项,但似乎都没有改变按下按钮会瞬间改变和切换的事实state
  3. 说到瞬间改变突出显示,它的持续时间似乎尽可能短,所以我必须实现一种“去抖动器”来防止-drawWithFrame:inView:被调用的频率超过指定的阈值。
  4. 我的纽扣电池也有属性myBackgroundColormyAlternateBackgroundColor. 我没有使用backgroundColor,因为我需要能够绘制自定义背景形状(填充矩形、填充圆形等)。时使用备用背景颜色highlighted。这里的问题是备用背景颜色应该#93edbf但似乎是#a1eecb!为了让它看起来像#93edbf,我需要将颜色设置为#84ecb2
  5. 到目前为止,这都是关于这个纽扣电池的一个特定实例。但在另一种情况下,替代背景根本没有绘制!我已经阅读了故事板代码,并且按钮尽可能相同。我的视图控制器代码同样会同时更新两个按钮单元的属性。为什么一个按钮的行为与另一个不同?
  6. 我希望按钮在鼠标按下时突出显示,而不是在鼠标抬起后“暂时”突出显示。我还没有在我的自定义单元格中实现这个。伙计,NSButtonCell 确实缺少一些东西。怎么会发生这样的事情?OS X 和 iOS 团队不曾相互交谈吗?

会是什么呢?

我已经验证了单元格的controlTint设置为NSClearControlTint. 我检查了背景过滤器、合成过滤器和内容过滤器,以防它们与此有关。

我知道 Apple 确实希望我们对 UI 元素使用他们的原生外观和感觉,但我从没想过他们会强制使用一些高光色调。

0 投票
1 回答
494 浏览

cocoa - 如何制作扁平的NSButton?

我怎样才能NSButton像这张照片一样制作公寓?

纽扣

我认为这张照片来自 Mac OS X >= 10.9。我有 Mac OS X 10.8.5。

0 投票
1 回答
213 浏览

cocoa - NSButton(Cell) 设置字体

从 10.9 开始,似乎NSButtonCell'ssetFont方法不再可用。
有没有办法(或类别)来(重新)实现它?

我不知道为什么 Apple 在按钮上强制使用自己的样式。
我正在尝试 2 天来设置我自己的自定义按钮的样式(我还需要一个类别来简单地更改按钮的文本颜色 - 耻辱)。

0 投票
0 回答
153 浏览

objective-c - NSButton 类型设置不正确

我有一个mac应用程序。

其中,我正在以编程方式创建一个 NSButton。

下面是我的代码。

所以它显示如下图片

我只想要一张图片。不是那个白色的背景。

我知道我在按钮类型或某处犯了一些愚蠢的错误。我已经尝试了很多,但没有运气。

另外,在mac OS X中我们可以在前面显示按钮吗?我们在ios中显示为bringsubviewtofront???

请帮助我。