The toggle button allows you to toggle the status item on/off. Clicking on the item reveals a menu with three options, two of which change the caption on the application's title bar while the third quits the application. This example application places a text status item named "Captioner" on the system-wide menu bar. Once you have the new status item object, you can assign it a title, a menu, a target-action, a tool tip, and so on. Following normal Cocoa memory management rules, you must retain the object returned by statusItemWithLength to keep it around. When deallocated, the status item removes itself from the status bar. Each status item then communicates with the status bar as its configuration changes. Instead, each application is responsible for retaining its own status items. The system status bar is shared by all applications and therefore cannot retain references to each application’s status item objects. You can use the constant NSVariableStatusItemLength to make the width variable based on the contents of the item. Pass the amount of space in pixels you need to display your status item. If you are displaying text, invoke statusItemWithLength to create a new status item and allocate space for it in the menu bar. You can use the constant NSSquareStatusItemLength to make the width the same as the status bar’s thickness.ĢB. If you are displaying an icon, invoke statusItemWithLength to create a new status item and allocate space for it in the menu bar. Obtain the system status bar with the systemStatusBar class method you should not allocate an instance of it yourself.ĢA. The items remain in the menu bar even when your application is not in the foreground.ġ. Status items appear on the right side of the menu bar, just to the left of the menu bar clock and Menu Extras, such as the Displays and Sound menus. It resides in the system-wide menu bar as shown above. Only one status bar, the system status bar, is available in macOS. For this reason, Apple recommends that you do not rely on them being available and always provide a user preference for hiding your application’s status items to free up space in the menu bar. As there is limited space in which to display status items, status items are not guaranteed to be available at all times. Use status items sparingly and only if the alternatives (such as a Dock menu, preference pane, or status window) are not suitable. A status item can be displayed with text or an icon, can provide a menu or send a target-action message when clicked. NSStatusBar is an object that manages a collection of status items that provide interaction with or feedback to the user. 4 Example code for an image status item.3 Example code for a text status item menu.
0 Comments
Leave a Reply. |