Mac Developer Library

Developer

AppKit Framework Reference NSStatusItem Class Reference

Options
Deployment Target:

On This Page
Language:

NSStatusItem

The NSStatusItem class represents the individual elements displayed within an NSStatusBar object. Instances are created by the NSStatusBar method statusItemWithLength:, which automatically adds the new status item to the status bar. The appearance and behavior of the status item are then set using the various NSStatusItem methods, such as setTitle: and setAction:.

Inheritance


Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.
  • Returns the status bar in which the receiver is displayed.

    Declaration

    Swift

    unowned(unsafe) var statusBar: NSStatusBar { get }

    Objective-C

    @property(readonly, assign) NSStatusBar *statusBar

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • setTitle: - setTitle: (OS X v10.10)

    Sets the string that is displayed at the receiver’s position in the status bar.

    Declaration

    Swift

    var title: String?

    Objective-C

    @property(copy) NSString *title

    Discussion

    If an image is also set, the title appears to the right of the image.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • title - title (OS X v10.10)

    Returns the string that is displayed at the receiver’s position in the status bar.

    Declaration

    Swift

    var title: String?

    Objective-C

    @property(copy) NSString *title

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Sets the attributed string that is displayed at the receiver’s position in the status bar.

    Declaration

    Swift

    @NSCopying var attributedTitle: NSAttributedString?

    Objective-C

    @property(copy) NSAttributedString *attributedTitle

    Discussion

    If an image is also set, the title appears to the right of the image.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Returns the attributed string that is displayed at the receiver’s position in the status bar

    Declaration

    Swift

    @NSCopying var attributedTitle: NSAttributedString?

    Objective-C

    @property(copy) NSAttributedString *attributedTitle

    Discussion

    .

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • setImage: - setImage: (OS X v10.10)

    Sets the image that is displayed at the receiver’s position in the status bar to image.

    Declaration

    Swift

    var image: NSImage?

    Objective-C

    @property(strong) NSImage *image

    Discussion

    If a title is also set, the image appears to the left of the title.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • image - image (OS X v10.10)

    Returns the image that is displayed at the receiver’s position in the status bar.

    Declaration

    Swift

    var image: NSImage?

    Objective-C

    @property(strong) NSImage *image

    Discussion

    Returns nil if an image has not been set.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Sets an alternate image to be displayed when a status bar item is highlighted.

    Declaration

    Swift

    var alternateImage: NSImage?

    Objective-C

    @property(strong) NSImage *alternateImage

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    Deprecated in OS X v10.10.

  • Returns the alternate image that is displayed when a status bar item is highlighted.

    Declaration

    Swift

    var alternateImage: NSImage?

    Objective-C

    @property(strong) NSImage *alternateImage

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    Deprecated in OS X v10.10.

  • Sets the amount of space in the status bar that should be allocated to the receiver.

    Declaration

    Swift

    var length: CGFloat

    Objective-C

    @property CGFloat length

    Parameters

    len

    If the status bar is horizontal, len is the horizontal space to allocate. In addition to a fixed length, len can be NSSquareStatusItemLength or NSVariableStatusItemLength to allow the status bar to allocate (and adjust) the space according to either the status bar’s thickness or the status item’s true size.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – length
    – statusItemWithLength: (NSStatusBar)

  • Returns the amount of space allocated to the receiver within its status bar.

    Declaration

    Swift

    var length: CGFloat

    Objective-C

    @property CGFloat length

    Discussion

    If the status bar is horizontal, the return value is the width of the status item. Besides a physical length, the return value may be NSSquareStatusItemLength or NSVariableStatusItemLength (see NSStatusBar Constants), if the status item size is either determined by the status bar thickness or allowed to vary according to the status item’s true size, respectively.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setLength:
    statusItemWithLength: (NSStatusBar)

  • Sets whether the receiver is highlighted when it is clicked.

    Declaration

    Swift

    var highlightMode: Bool

    Objective-C

    @property BOOL highlightMode

    Discussion

    The default is NOfalse, which means the receiver isn’t highlighted when it is clicked.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Returns whether the receiver is highlighted when clicked.

    Declaration

    Swift

    var highlightMode: Bool

    Objective-C

    @property BOOL highlightMode

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • setToolTip: - setToolTip: (OS X v10.10)

    Sets the tool tip string that is displayed when the cursor pauses over the receiver.

    Declaration

    Swift

    var toolTip: String?

    Objective-C

    @property(copy) NSString *toolTip

    Parameters

    toolTip

    A string that functions as the title of the status item.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

    See Also

    – toolTip

  • toolTip - toolTip (OS X v10.10)

    Returns the tool tip string that is displayed when the cursor pauses over the receiver.

    Declaration

    Swift

    var toolTip: String?

    Objective-C

    @property(copy) NSString *toolTip

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

    See Also

    – setToolTip:

  • setEnabled: - setEnabled: (OS X v10.10)

    Sets whether the receiver is enabled to respond to clicks.

    Declaration

    Swift

    var enabled: Bool

    Objective-C

    @property(getter=isEnabled) BOOL enabled

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

    See Also

    – isEnabled

  • isEnabled - isEnabled Available in OS X v10.0 through OS X v10.9

    Returns whether the receiver is enabled and responding to clicks.

    Declaration

    Objective-C

    - (BOOL)isEnabled

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

    See Also

    – setEnabled:

  • setTarget: - setTarget: (OS X v10.10)

    Sets the target object to which the receiver’s action message is sent when the receiver is clicked.

    Declaration

    Swift

    weak var target: AnyObject?

    Objective-C

    @property(weak) id target

    Discussion

    If the receiver has a menu set, the action is not sent to target when the receiver is clicked; instead, the click causes the menu to appear.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • target - target (OS X v10.10)

    Returns the target to which the receiver’s action message is sent when the user clicks the receiver.

    Declaration

    Swift

    weak var target: AnyObject?

    Objective-C

    @property(weak) id target

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • setAction: - setAction: (OS X v10.10)

    Sets the selector that is sent to the receiver’s target when the receiver is clicked.

    Declaration

    Swift

    var action: Selector

    Objective-C

    @property SEL action

    Discussion

    If the receiver has a menu set, action is not sent to the target when the receiver is clicked; instead, the click causes the menu to appear.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • action - action (OS X v10.10)

    Returns the selector that is sent to the receiver’s target when the user clicks the receiver.

    Declaration

    Swift

    var action: Selector

    Objective-C

    @property SEL action

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Sets the selector that is sent to the receiver’s target when the receiver is double-clicked.

    Declaration

    Swift

    var doubleAction: Selector

    Objective-C

    @property SEL doubleAction

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    Deprecated in OS X v10.10.

  • Returns the selector that is sent to the receiver’s target when the user double-clicks the receiver.

    Declaration

    Swift

    var doubleAction: Selector

    Objective-C

    @property SEL doubleAction

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    Deprecated in OS X v10.10.

  • Sets the conditions on which the receiver sends action messages to its target.

    Declaration

    Swift

    func sendActionOn(_ mask: Int) -> Int

    Objective-C

    - (NSInteger)sendActionOn:(NSInteger)mask

    Parameters

    mask

    Takes one or more of the following bit masks described in Constants section of the NSEvent class reference: NSLeftMouseUpMask, NSLeftMouseDownMask, NSLeftMouseDraggedMask, and NSPeriodicMask. Bitwise-OR multiple bit masks.

    Return Value

    A bit mask containing the previous settings. This bit mask uses the same values as specified in the mask parameter.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Sets the pull-down menu that is displayed when the receiver is clicked.

    Declaration

    Swift

    var menu: NSMenu?

    Objective-C

    @property(strong) NSMenu *menu

    Parameters

    menu

    The NSMenu object to display.

    Discussion

    When set, the receiver’s single click action behavior is not used. The menu can be removed by setting menu to nil.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the drop-down menu that is displayed when the receiver is clicked.

    Declaration

    Swift

    var menu: NSMenu?

    Objective-C

    @property(strong) NSMenu *menu

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setMenu:

  • Displays a menu under a custom status bar item.

    Declaration

    Swift

    func popUpStatusItemMenu(_ menu: NSMenu)

    Objective-C

    - (void)popUpStatusItemMenu:(NSMenu *)menu

    Parameters

    menu

    The NSMenu object to display.

    Discussion

    You can use this method to cause a popup menu to appear under a custom status bar item when the user clicks the item. Note that the view of the receiver must exist (that is, it must not be nil).

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    Deprecated in OS X v10.10.

  • setView: - setView: (OS X v10.10)

    Sets the custom view that is displayed at the receiver’s position in the status bar.

    Declaration

    Swift

    var view: NSView?

    Objective-C

    @property(strong) NSView *view

    Parameters

    view

    The NSView object representing the custom view.

    Discussion

    Setting a custom view overrides all the other appearance and behavior settings defined by NSStatusItem. The custom view is responsible for drawing itself and providing its own behaviors, such as processing mouse clicks and sending action messages.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

    See Also

    – view

  • view - view (OS X v10.10)

    Returns the custom view that is displayed at the receiver’s position in the status bar.

    Declaration

    Swift

    var view: NSView?

    Objective-C

    @property(strong) NSView *view

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

    See Also

    – setView:

  • Draws the menu background pattern for a custom status-bar item in regular or highlight pattern.

    Declaration

    Swift

    func drawStatusBarBackgroundInRect(_ rect: NSRect, withHighlight highlight: Bool)

    Objective-C

    - (void)drawStatusBarBackgroundInRect:(NSRect)rect withHighlight:(BOOL)highlight

    Parameters

    rect

    A rectangle defining the area of a custom status-bar item.

    highlight

    YEStrue to draw the background pattern in the standard highlight pattern, NO to not highlight the pattern..

    Discussion

    You can use this method to help a custom status-bar item emulate the behavior of a standard item.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    Deprecated in OS X v10.10.

    See Also

    – setView: