简体   繁体   中英

add customView to NSStatusItem

I would like to create a status bar application which has non-menu style. same as FaceTab for facebook (I mean only interface, not functional)... this is my codes:

-(void)awakeFromNib{
    statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
    [statusItem setView:customView];
    //[statusItem setMenu:menu];
    [statusItem setTitle:@"Status"];
    [statusItem setHighlightMode:YES];
}

..... so once I Use NSMenu everything works fine but when I use NSView and CustomView outlet nothing appear on menu bar. Help plz!

涉及到几个活动部分,所以我能给出的最好建议是查看 Vadim Shpakovski 的这个优秀示例项目

At the end of your awakeFromNib method, you may need to call retain on the statusItem so that it doesn't go out of scope. I was struggling with this same problem, and adding [statusItem retain]; fixed it so that I now see my Status menu in the Mac OS status bar.

-(void)awakeFromNib{
    statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
    [statusItem setView:customView];

    // in my code, this is uncommented, and menu is an instance variable.
    //[statusItem setMenu:menu];

    [statusItem setTitle:@"Status"];
    [statusItem setHighlightMode:YES];

    // this was needed to get the icon to display in the status bar.
    [statusItem retain];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM