简体   繁体   English

将 customView 添加到 NSStatusItem

[英]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:与 Facebook 的 FaceTab 相同(我的意思是只有界面,没有功能)……这是我的代码:

-(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. ..... 所以一旦我使用 NSMenu 一切正常,但是当我使用 NSView 和 CustomView 插座时,菜单栏上没有任何显示。 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.在awakeFromNib 方法结束时,您可能需要在statusItem 上调用retain,以便它不会超出范围。 I was struggling with this same problem, and adding [statusItem retain];我正在努力解决同样的问题,并添加[statusItem retain]; fixed it so that I now see my Status menu in the Mac OS status bar.修复了它,以便我现在可以在 Mac OS 状态栏中看到我的状态菜单。

-(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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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