NSButton in NSToolbar item: click issue

≡放荡痞女 提交于 2019-12-13 04:30:23

问题


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

This is when i click on it (and not rise the left mouse button)

Can anyone tell me how to fix that? thanks!


回答1:


Have you tried changing the button type to NSMomentaryChangeButton?

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.



来源:https://stackoverflow.com/questions/18145261/nsbutton-in-nstoolbar-item-click-issue

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