所以我对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但没有运气,也试过自己设置,但有同样的问题,但没有什么改进.