添加到OS X状态托盘

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了添加到OS X状态托盘相关的知识,希望对你有一定的参考价值。

  1. @interface Tray : NSObject <NSApplicationDelegate> {
  2. NSStatusItem *trayItem;
  3. }
  4. @end
  5.  
  6. @implementation Tray
  7.  
  8. - (IBAction)testAction:(id)sender;
  9. {
  10. NSLog(@"Hello World");
  11. }
  12.  
  13. - (IBAction)quitAction:(id)sender;
  14. {
  15. [NSApp terminate:sender];
  16. }
  17.  
  18. - (void)applicationDidFinishLaunching:(NSNotification *)note;
  19. {
  20. NSZone *zone = [NSMenu menuZone];
  21. NSMenu *menu = [[[NSMenu allocWithZone:zone] init] autorelease];
  22. NSMenuItem *item;
  23.  
  24. item = [menu addItemWithTitle:@"Testing" action:@selector(testAction:) keyEquivalent:@""];
  25. [item setTarget:self];
  26.  
  27. item = [menu addItemWithTitle:@"Quit" action:@selector(quitAction:) keyEquivalent:@""];
  28. [item setTarget:self];
  29.  
  30. trayItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
  31. [trayItem setMenu:menu];
  32. [trayItem setHighlightMode:YES];
  33. [trayItem setTitle:@"HERE"];
  34. }
  35.  
  36. - (void)dealloc;
  37. {
  38. [trayItem release];
  39. [super dealloc];
  40. }
  41.  
  42. @end
  43.  

以上是关于添加到OS X状态托盘的主要内容,如果未能解决你的问题,请参考以下文章

添加到OS X状态托盘

添加到OS X状态托盘

添加到OS X状态托盘

添加到OS X状态托盘

添加到OS X状态托盘

添加到OS X状态托盘