NSButton在NSToolbar项目:点击问题 [英] NSButton in NSToolbar item: click issue
问题描述
我想使用一个NSButton配置为在我的 NSToolbarItem
中只显示一个图像。该项目是在IB中创建的,添加按钮的代码是:
I want to use a NSButton configured to show only an image in my NSToolbarItem
. The item is created in IB and the code to add the button to it is:
NSButton *button = [[NSButton alloc]init];
[button setImage:[NSImage imageNamed:@"StarEmpty"]];
[button setAlternateImage:[NSImage imageNamed:@"StarFull"]];
[button setImagePosition:NSImageOnly];
[button setBordered:NO];
[self.toolbarItem setView:button];
问题是,当我点击图像而不是替代图像时,会显示较亮的背景。我链接图片来解释问题。
The problem is that when i click on the image instead of the alternate image a lighter background is shown. I link the image to explain the problem.
这是正常状态,它是确定
This is the normal state and it's ok
这是当我点击它
任何人都可以告诉我如何解决这个问题?谢谢!
Can anyone tell me how to fix that? thanks!
推荐答案
您是否尝试将按钮类型更改为 NSMomentaryChangeButton
?
Have you tried changing the button type to NSMomentaryChangeButton
?
NSMomentaryChangeButton:按住按钮时,会显示备用
图像和备用标题。当未按下按钮时,显示正常图像和标题
。此选项在Interface Builder的Button Inspector中称为
Momentary Change。可在OS X v10.0及更高版本中使用
。
NSMomentaryChangeButton : While the button is held down, the alternate image and alternate title are displayed. The normal image and title are displayed when the button isn’t pressed. This option is called "Momentary Change" in Interface Builder’s Button Inspector. Available in OS X v10.0 and later.
这篇关于NSButton在NSToolbar项目:点击问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!