OSX状态栏图像大小 - 可可

Bol*_*ich 4 macos cocoa objective-c nsstatusitem nsstatusbar

所以我对NSStatusBar项目的图像有问题,看起来图像正在远离其他菜单项,正如您在此图片中看到的那样.但是当菜单栏处于非活动状态时(如我在其他显示器上或不在应用程序中),问题不会发生,因为您可以在此图片中看到.我很确定我的代码是正确的.

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"]];
}
Run Code Online (Sandbox Code Playgroud)

我查看了这个问题:在可可状态应用程序中显示图像,但问题仍然存在,所以我不知道还能做什么,感谢您的帮助!PS:我认为的问题是NSVariableStatusItemLength,我试过NSSquareStatusItemLength但没有运气,也试过自己设置,但有同样的问题,但没有什么改进.

Tho*_*ing 9

当实现NSStatusItem菜单栏中显示的好看时,我也遇到了一些问题.
当项目符合以下标准(以及随附资产)时,我获得了最佳结果

  • 状态图像应基于PDF
  • ...并使用"模板"后缀(更多关于此处)
  • 满足上述条件将为您提供HiDPI支持以及Light&Dark菜单栏的正确渲染
  • 图像的大小应设置为(18.0,18.0)
  • 要获得与状态栏中默认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
Run Code Online (Sandbox Code Playgroud)