Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. // AppDelegate.h & AppDelegate.m are sample code generated by XCode Cocoa
  2. // app wizard.
  3.  
  4. // AppDelegate.h
  5. @interface AppDelegate : NSObject <NSApplicationDelegate>
  6. {
  7. // Instance variable ensures that ARC does not clean it up
  8. NSStatusItem *theItem;
  9. }
  10. - (void) activateStatusMenu;
  11. - (void) activateGUI;
  12. - (void) quitApp;
  13. @end
  14.  
  15. // AppDelegate.m
  16.  
  17. @interface AppDelegate ()
  18.  
  19. @property (weak) IBOutlet NSWindow *window;
  20. @end
  21.  
  22. @implementation AppDelegate
  23.  
  24. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  25. // Insert code here to initialize your application
  26. [self activateStatusMenu];
  27. }
  28.  
  29.  
  30. - (void)applicationWillTerminate:(NSNotification *)aNotification {
  31. // Insert code here to tear down your application
  32. }
  33.  
  34. /**
  35. * Create the Status icon & its menu
  36. */
  37. - (void)activateStatusMenu
  38. {
  39. NSStatusBar *bar = [NSStatusBar systemStatusBar];
  40.  
  41. theItem = [bar statusItemWithLength:NSSquareStatusItemLength];
  42. // Requires project to have asset named Status, which consists of one 16x16 icon
  43. [[theItem button] setImage: [NSImage imageNamed:@"Status"]];
  44. [theItem setHighlightMode:YES];
  45.  
  46. NSMenu* menu = [[NSMenu alloc] init];
  47. NSMenuItem* item = [[NSMenuItem alloc] init];
  48. [item setTitle:@"StatusBarProgram"];
  49. [item setAction:@selector(activateGUI)];
  50. [menu addItem: item];
  51.  
  52. item = [[NSMenuItem alloc] init];
  53. [item setTitle:@"Quit"];
  54. [item setAction:@selector(quitApp)];
  55. [menu addItem: item];
  56.  
  57. [theItem setMenu:menu];
  58. }
  59.  
  60. - (void) activateGUI
  61. {
  62. NSLog(@"Launch GUI");
  63. }
  64.  
  65. - (void) quitApp
  66. {
  67. [NSApp terminate:self];
  68. }
  69. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement