Mac Developer Library

Developer

AppKit Framework Reference NSStatusBar Class Reference

Options
Deployment Target:

On This Page
Language:

NSStatusBar

Inheritance


Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.

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.

Use status items sparingly and only if the alternatives (such as a Dock menu, preference pane, or status window) are not suitable. Because there is limited space in which to display status items, status items are not guaranteed to be available at all times. For this reason, 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.

  • 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

    Objective-C

    @import AppKit;

    Swift

    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

    Objective-C

    @import AppKit;

    Swift

    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

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • vertical vertical Property

    A Boolean value indicating whether the status bar has a vertical orientation. (read-only)

    Declaration

    Swift

    var vertical: Bool { get }

    Objective-C

    @property(getter=isVertical, readonly) BOOL vertical

    Discussion

    When the value of this property is YEStrue, the status bar has a vertical orientation. The status bar returned by the systemStatusBar method is horizontal and has the value NOfalse for this property.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • thickness thickness Property

    The thickness of the status bar, in pixels. (read-only)

    Declaration

    Swift

    var thickness: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat thickness

    Discussion

    The default value of this property is 20.0. The status bar returned by the systemStatusBar has a thickness of 22 pixels, which corresponds to the thickness of the menu bar.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Constants used by the statusItemWithLength: method.

    Declaration

    Swift

    let NSSquareStatusItemLength: CGFloat let NSVariableStatusItemLength: CGFloat

    Objective-C

    static const CGFloat NSVariableStatusItemLength = -1.0; static const CGFloat NSSquareStatusItemLength = -2.0;

    Constants

    • NSSquareStatusItemLength

      NSSquareStatusItemLength

      Sets the status item length to the status bar thickness.

      Available in OS X v10.10 and later.

    • NSVariableStatusItemLength

      NSVariableStatusItemLength

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

      Available in OS X v10.10 and later.