簡體   English   中英

將 customView 添加到 NSStatusItem

[英]add customView to NSStatusItem

我想創建一個非菜單樣式的狀態欄應用程序。 與 Facebook 的 FaceTab 相同(我的意思是只有界面,沒有功能)……這是我的代碼:

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

..... 所以一旦我使用 NSMenu 一切正常,但是當我使用 NSView 和 CustomView 插座時,菜單欄上沒有任何顯示。 請幫忙!

涉及到幾個活動部分,所以我能給出的最好建議是查看 Vadim Shpakovski 的這個優秀示例項目

在awakeFromNib 方法結束時,您可能需要在statusItem 上調用retain,以便它不會超出范圍。 我正在努力解決同樣的問題,並添加[statusItem retain]; 修復了它,以便我現在可以在 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