Mac Developer Library

Developer

AppKit Framework Reference NSStatusBar Class Reference

Options
Deployment Target:

On This Page
Language:

NSStatusBar

The NSStatusBar class defines an object that manages a collection of NSStatusItem objects displayed within the system-wide menu bar. A status item can be displayed with text or an icon, can provide a menu and a target-action message when clicked, or can be a fully customized view that you create. More...

Inheritance


Conforms To


Import Statement


import AppKit @import AppKit;

Availability


Available in OS X v10.0 and later.
  • Returns the system-wide status bar located in the menu bar.

    Declaration

    Swift

    class func systemStatusBar() -> NSStatusBar

    Objective-C

    + (NSStatusBar *)systemStatusBar

    Return Value

    The shared status bar object.

    Discussion

    The status bar begins at the right side of the menu bar (to the left of Menu Extras and the menu bar clock) and grows to the left as NSStatusItem objects are added to it.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns a newly created status item that has been allotted a specified space within the status bar.

    Declaration

    Swift

    func statusItemWithLength(_ length: CGFloat) -> NSStatusItem

    Objective-C

    - (NSStatusItem *)statusItemWithLength:(CGFloat)length

    Parameters

    length

    A constant that specifies whether the status item is of fixed width, or variable width. The valid constants are described in Status Bar Item Length.

    Return Value

    An NSStatusItem object or nil if the item could not be created.

    Discussion

    The receiver does not retain a reference to the status item, so you need to retain it. Otherwise, the object is removed from the status bar when it is deallocated.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Removes the specified status item from the receiver.

    Declaration

    Swift

    func removeStatusItem(_ item: NSStatusItem)

    Objective-C

    - (void)removeStatusItem:(NSStatusItem *)item

    Parameters

    item

    The NSStatusItem object to remove.

    Discussion

    Status items to the left of the specified one in the status bar shift to the right to reclaim its space.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Returns whether the receiver has a vertical orientation.

    Declaration

    Objective-C

    - (BOOL)isVertical

    Return Value

    YEStrue if the receiver has a vertical orientation, otherwise NOfalse.

    Discussion

    The status bar returned by systemStatusBar is horizontal, so it always returns NOfalse.

    Import Statement

    Availability

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

  • Returns the thickness of the status bar.

    Declaration

    Swift

    var thickness: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat thickness

    Return Value

    The thickness of the status bar in pixels.

    Discussion

    The status bar returned by systemStatusBar has a thickness of 22 pixels, the thickness of the menu bar.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • The following constants are used by statusItemWithLength:.

    Declaration

    Objective-C

    #define NSVariableStatusItemLength (-1) #define NSSquareStatusItemLength (-2)

    Constants

    • NSSquareStatusItemLength

      NSSquareStatusItemLength

      Sets the status item length to the status bar thickness.

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

    • NSVariableStatusItemLength

      NSVariableStatusItemLength

      Makes the status item length dynamic, adjusting to the width of its contents.

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

    Import Statement