我在应用程序的工具栏中有两个自定义 NSToolbarItems。每个类都有一个 NSButton ,我在其中设置按钮,然后将工具栏项的视图设置为按钮(例如停止按钮项):
@implementation RBSStopButtonToolbarItem
@synthesize button = _button;
-(id)initWithItemIdentifier:(NSString *)itemIdentifier
{
self = [super initWithItemIdentifier:itemIdentifier];
if(self)
{
// create button
_button = [[NSButton alloc] init];
// set the frame and bounds to be the same size
//[_button setFrameSize:NSMakeSize(64.0, 64.0)];
//[_button setBoundsSize:NSMakeSize(64.0, 64.0)];
// button will not have a visible border
[_button setBordered:NO];
// set the original and alternate images...names are "opposite"
[_button setImage:[NSImage imageNamed:@"StopButtonAlternateIcon"]];
[_button setAlternateImage:[NSImage imageNamed:@"StopButtonIcon"]];
// image position
[_button setImagePosition:NSImageOnly];
// set button type
[_button setButtonType:NSMomentaryChangeButton];
// button is transparent
[_button setTransparent:YES];
// set the toolbar item view to the button
[self setView:_button];
}
return self;
}
我对每个自定义 NSToolbarItem 都有一个 IBOutlet:
// toolbar item for start button
IBOutlet RBSStartButtonToolbarItem *_startButtonToolbarItem;
// toolbar item for stop button
IBOutlet RBSStopButtonToolbarItem *_stopButtonToolbarItem;
但是我没有在自定义视图工具栏项目中看到图像:
图像是 .icns 类型。我试图遵循的示例在这里:
NSToolbar 项目中的 NSButton:单击问题
有没有经验的人可以提供建议?