![]() ![]() Here's the full code for the appDelegate.m file those that want to copy and paste the code directly In the next part of this tutorial, we shall look at using the badge feature on the dock icon and understanding how that works. While the app also creates a main window, if your tool does not require the main window then you could either hide it or remove it entirely. Additional handlers can be set up for other menu items.Īnd one can also add a separator to the menu using [theMenu you select the menu item four, a message is printed to the console window (only when run from xCode). (void)onHandleFour:(id) selected Four") Īnd this can be assigned to the menu item as ![]() ![]() Here's an example of declaring a handler and then assigning it to a menu item [theMenu action:nil action:nil action:nil the menu itemsThe various menu items can be handled by adding a handler (function) or using the system functions like we did with the quit menu item, where we called terminate We can also add more items simply by create new menuItems. If we select theQuit menu option here, the app quits. Now we can see the menu drop down when we click on the icon. We declare a variable theMenu as followsĪnd the menus is created as follows by placing this code before where we created our statusbar So first we declare the variable and create the menu. To do that, we need to create and set the menu for this. Let us add a drop down menu to this icon, as we set out to do in the first place. To ensure that we do not have memory leaks, we also add the code to release theMenu and statusItem that we allocated. Now if you run the app, you can see that it responds to selecting the icon, highlighting the icon and unhighlighting it on release. However if you click on the icon, nothing happens, it is almost as if it does not respond. Now if you hover the mouse over the icon, you will see the tooltip pop-up. Let us have a tooltip text added to the icon, the way to do so is very simple and easy, we simply use If you hover your mouse over it or attempt to click it, nothing happens. In the image you can see the icon next to the Dropbox icon. [statusItem setImage:[NSImage add the following code on top just after the implementationĪnd now if you run the app, you would see the icon.png image on the menubar on top right where you see the user and the time and the app menus. spot the -(void)applicationDidFinishLaunching:(NSNotification *)aNotificationfunction and add the following code to the function under that. Select the copy items into destination group's folderģ. Drag drop the Icon.png file to the sidebar to the left. We add an image to our project, the icon that we want to use for the project called icon.png (you can download it from here or create a new icon which is 16x16)Ģ. If you press run, the app compiles and creates a window on the screen.ġ. Click on the AppDelegate.m which can be found in the list of files created by xcode for youĤ. You can fill in the other details like your company name, the identifier, class prefix (you can leave this blank if you want), App Store Category, etc.ģ. Fill in the details of the app, for this example we are calling it menuBar. Note: Ensure that you have select Application under OSX not iOS.Ģ. start xCode and select a new project, in the sidebar select "Application" under the OSX. In this series of how to articles, we shall look at creating an app for the Mac OSX using Objective-C and xCode.ġ. With most of the iOS developers now having access to a Mac and xCode, this is the easiest jump to creating your own tool for the Mac OSX. A new tutorial for you and more so in the genre of developing desktop tools. ![]()
0 Comments
Leave a Reply. |