在可可状态应用程序中显示图像

use*_*496 9 cocoa objective-c nsimage nsstatusitem

嗨,我开发了一个可可状态应用程序.例如,当我放一个长标题时,它无法显示,如果我将图像作为图标也无法显示,但如果我放一个小标题就能正常工作.如何解决此问题并显示图像?

statusItem = [[[NSStatusBar systemStatusBar] 
    statusItemWithLength:NSSquareStatusItemLength] retain];    

[statusItem setMenu:menu]; 
//[statusItem setTitle:@"Notif "]; 
[statusItem setImage:[NSImage imageNamed:@"image"]]; 
[statusItem setHighlightMode:YES];
Run Code Online (Sandbox Code Playgroud)

Mat*_*ler 9

基本上

NSStatusItem *statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
NSImage* icon = [NSImage alloc] initWith ...]
[statusItem setImage:icon];
Run Code Online (Sandbox Code Playgroud)

但是你的图像必须是正确的尺寸(小于20*20)

  • 对于非Retina,图像的最大尺寸为21x21而不是20x20.对于视网膜,最大值为41x41; 请参阅[我的博客文章](http://alastairs-place.net/blog/2013/07/23/nsstatusitem-what-size-should-your-icon-be/)了解更多信息. (2认同)