2015-11-14 79 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! –