2015-11-14 53 views
2

所以我有一個NSStatusBar項目的圖像的問題,它似乎像圖像推開了其餘的菜單項as you can see in this picture.但是,當菜單欄不活動(如在我爲我的其他顯示器上或者沒有在應用程序)的問題不會發生as you can see in this picture。我很確定我的代碼是正確的。OSX狀態欄圖像大小 - 可可

statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength]; 
[statusItem setHighlightMode:YES]; 
[statusItem setAction:@selector(openWindow)]; 
[statusItem setTarget:self]; 

if ([[[NSAppearance currentAppearance] name] containsString:NSAppearanceNameVibrantDark]) { 
    [statusItem setImage:[NSImage imageNamed:@"whiteMenu.png"]]; 
} else { 
    [statusItem setImage:[NSImage imageNamed:@"blackMenu.png"]]; 
} 

我認爲這一問題:Display image in a cocoa status app,但問題仍然存在,所以我不知道自己能做什麼,感謝您的幫助! PS:我認爲這個問題是NSVariableStatusItemLength,我試圖NSSquareStatusItemLength但沒有運氣,也嘗試設置它自己,但同樣的問題,但幾乎沒有改善。

回答

4

實現一個漂亮的NSStatusItem顯示在菜單欄時,我也有幾個問題。
我得到了最好的結果時,下列條件得到滿足爲

  • 狀態圖像應基於PDF的
  • 項目(以及伴隨的資產)...和使用「模板」後綴(更有關here
  • 符合上述會給你輕&黑暗菜單欄
  • 圖像的大小應設置爲(18.0,18.0)
  • 要獲得SAM HiDPI支持和適當的渲染Ë突出在狀態欄默認OS X的項目,highlightMode必須是在和項目都必須有一個相關的NSMenu

這個片段會給你在系統主菜單好看NSStatusItem一個基本的應用程序(我這裏使用的提供圖像的系統,但你可以用自定義的18x18 PDF相同的結果與「模板」的後綴名):

@interface AppDelegate() 

@property NSStatusItem* statusItem; 
@property (weak) IBOutlet NSMenu *statusMenu; 

@end 

@implementation AppDelegate 

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { 
    NSImage* statusImage = [NSImage imageNamed:NSImageNameActionTemplate]; 
    statusImage.size = NSMakeSize(18.0, 18.0); 
    self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength]; 
    self.statusItem.image = statusImage; 
    self.statusItem.highlightMode = YES; 
    self.statusItem.enabled = YES; 
    self.statusItem.menu = self.statusMenu; 
} 

- (void)applicationWillTerminate:(NSNotification *)aNotification { 
    // Insert code here to tear down your application 
} 

@end 
+0

你的答案是好多了,但事實證明,另一種答案我的問題是,只是爲了擺脫這是控制狀態欄的計時器,因爲我曾經有過一個定時器來檢查菜單欄的外觀發生了變化不過謝謝!沒有線索我不得不使用pdf! –