我对这个项目的灵感来自Droplr和CloudApp mac菜单栏应用程序.我一直在尝试实现这里解释的代码.
但是,当我实现代码时,菜单栏图像消失了.这是我创建状态项的代码:
- (id)init {
self = [super init];
if (self != nil) {
// Install status item into the menu bar
NSStatusItem *statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:STATUS_ITEM_VIEW_WIDTH];
_statusItemView = [[StatusItemView alloc] initWithStatusItem:statusItem];
_statusItemView.image = [NSImage imageNamed:@"Status"];
_statusItemView.alternateImage = [NSImage imageNamed:@"StatusHighlighted"];
_statusItemView.action = @selector(togglePanel:);
StatusItemView* dragView = [[StatusItemView alloc] initWithFrame:NSMakeRect(0, 0, 24, 24)];
[statusItem setView:dragView];
[dragView release];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
这是我的查看文件:
#import "StatusItemView.h"
@implementation StatusItemView
@synthesize statusItem = _statusItem;
@synthesize image = _image;
@synthesize alternateImage = …Run Code Online (Sandbox Code Playgroud)