Mac Developer Library

Developer

AppKit Framework Reference NSMenuItemCell Class Reference

Options
Deployment Target:

On This Page
Language:

NSMenuItemCell

NSMenuItemCell is a class that handles the measurement and display of a single menu item in its encompassing frame. Instances of NSMenuItemCell work in conjunction with an NSMenuView object to control the overall appearance of the menu. More...

Import Statement


import AppKit @import AppKit;

Availability


Available in OS X v10.0 and later.
  • Returns the NSMenuItem object associated with the receiver.

    Declaration

    Swift

    var menuItem: NSMenuItem?

    Objective-C

    @property(strong) NSMenuItem *menuItem

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the NSMenuItem object associated withthe receive.

    Declaration

    Swift

    var menuItem: NSMenuItem?

    Objective-C

    @property(strong) NSMenuItem *menuItem

    Parameters

    item

    The NSMenuItem object to set.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – menuItem

  • Returns the menu view associated with the receiver.

    Declaration

    Objective-C

    - (NSMenuView *)menuView

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Not available to 64-bit applications.

  • Sets the menu view for the receiver.

    Declaration

    Objective-C

    - (void)setMenuView:(NSMenuView *)menuView

    Parameters

    menuView

    The NSMenuView object to associate with the receiver.

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Not available to 64-bit applications.

    See Also

    – menuView

  • Calculates the minimum required width and height of the receiver’s menu item.

    Declaration

    Swift

    func calcSize()

    Objective-C

    - (void)calcSize

    Discussion

    The calculated values are cached for future use. This method also calculates the sizes of individual components of the cell’s menu item and caches those values.

    This method is invoked automatically when necessary. You should not need to invoke it directly.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – needsSizing

  • Returns YEStrue if the size of the menu item needs to be calculated; otherwise returns NOfalse.

    Declaration

    Swift

    var needsSizing: Bool

    Objective-C

    @property BOOL needsSizing

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets a flag that indicates whether or not the menu item must be resized.

    Declaration

    Swift

    var needsSizing: Bool

    Objective-C

    @property BOOL needsSizing

    Parameters

    flag

    If flag is YEStrue, the next attempt to obtain any size-related information from this menu item cell invokes the calcSize method to recalculate the information. If flag is NOfalse, the next attempt to obtain size-related information returns the currently cached values.

    Discussion

    Subclasses that drastically change the way a menu item is drawn may need to invoke this method to recalculate the menu item information. Other parts of your application should not need to invoke this method directly. The cell invokes this method as necessary when the content of its menu item changes.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – needsSizing

  • Returns the width of the image associated with a menu item.

    Declaration

    Swift

    var imageWidth: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat imageWidth

    Discussion

    You can associate an image with a menu item using the NSMenuItem setImage: method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the width of the menu item text.

    Declaration

    Swift

    var titleWidth: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat titleWidth

    Discussion

    To set the menu item text, use NSMenuItem’s setTitle: method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the width of the key equivalent associated with the menu item.

    Declaration

    Swift

    var keyEquivalentWidth: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat keyEquivalentWidth

    Discussion

    You can associate a key equivalent with a menu item using the NSMenuItem method setKeyEquivalent:.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the width of the image used to indicate the state of the menu item.

    Declaration

    Swift

    var stateImageWidth: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat stateImageWidth

    Discussion

    If the menu item has multiple images associated with it (to indicate any of the available states: on, off, or mixed), this method returns the width of the largest image. You can set the state images for a menu item using the NSMenuItem methods setOnStateImage:, setOffStateImage:, and setMixedStateImage:.

    To change the state of the cell’s menu item, use the NSMenuItem method setState:.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – calcSize
    – needsSizing
    – setState: (NSMenuItem)

  • Draws the borders and background associated with the receiver’s menu item (if any).

    Declaration

    Swift

    func drawBorderAndBackgroundWithFrame(_ cellFrame: NSRect, inView controlView: NSView)

    Objective-C

    - (void)drawBorderAndBackgroundWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

    Parameters

    cellFrame

    A rectangle defining the receiver's frame area.

    controlView

    The view object that contains this cell (usually an NSControl object).

    Discussion

    This method invokes the NSCell method imageRectForBounds:, passing it cellFrame, to calculate the rectangle in which to draw the image. The cell invokes this method before invoking the methods to draw the other menu item components.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – drawWithFrame:inView: (NSCell)

  • Draws the image associated with the menu item.

    Declaration

    Swift

    func drawImageWithFrame(_ cellFrame: NSRect, inView controlView: NSView)

    Objective-C

    - (void)drawImageWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

    Parameters

    cellFrame

    A rectangle defining the receiver's frame area.

    controlView

    The view object that contains this cell (usually an NSControl object).

    Discussion

    This method invokes the NSCell method imageRectForBounds:, passing it cellFrame, to calculate the rectangle in which to draw the image. This method is invoked by the cell’s drawWithFrame: method. You should not need to invoke it directly. Subclasses may override this method to control the drawing of the image.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Draws the key equivalent associated with the menu item.

    Declaration

    Swift

    func drawKeyEquivalentWithFrame(_ cellFrame: NSRect, inView controlView: NSView)

    Objective-C

    - (void)drawKeyEquivalentWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

    Parameters

    cellFrame

    A rectangle defining the receiver's frame area.

    controlView

    The view object that contains this cell (usually an NSControl object).

    Discussion

    This method invokes keyEquivalentRectForBounds:, passing it cellFrame, to calculate the rectangle in which to draw the key equivalent. This method is invoked by the cell’s drawWithFrame: method. You should not need to invoke it directly. Subclasses may override this method to control the drawing of the key equivalent.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Draws a menu item separator.

    Declaration

    Swift

    func drawSeparatorItemWithFrame(_ cellFrame: NSRect, inView controlView: NSView)

    Objective-C

    - (void)drawSeparatorItemWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

    Parameters

    cellFrame

    A rectangle defining the receiver's frame area.

    controlView

    The view object that contains this cell (usually an NSControl object).

    Discussion

    This method uses the cellFrame parameter to calculate the rectangle in which to draw the menu item separator. This method uses the controlView to determine whether the separator item should be drawn normally or flipped.

    You should not need to invoke this method directly. Subclasses may override this method to control the drawing of the separator.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Draws the state image associated with the menu item.

    Declaration

    Swift

    func drawStateImageWithFrame(_ cellFrame: NSRect, inView controlView: NSView)

    Objective-C

    - (void)drawStateImageWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

    Parameters

    cellFrame

    A rectangle defining the receiver's frame area.

    controlView

    The view object that contains this cell (usually an NSControl object).

    Discussion

    This method invokes stateImageRectForBounds:, passing it cellFrame, to calculate the rectangle in which to draw the state image. This method is invoked by the cell’s drawWithFrame: method. You should not need to invoke it directly. Subclasses may override this method to control the drawing of the state image.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Draws the title associated with the menu item.

    Declaration

    Swift

    func drawTitleWithFrame(_ cellFrame: NSRect, inView controlView: NSView)

    Objective-C

    - (void)drawTitleWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

    Parameters

    cellFrame

    A rectangle defining the receiver's frame area.

    controlView

    The view object that contains this cell (usually an NSControl object).

    Discussion

    This method invokes titleRectForBounds:, passing it cellFrame, to calculate the rectangle in which to draw the title. The controlView parameter specifies the view that contains this cell.This method is invoked by the cell’s drawWithFrame: method. You should not need to invoke it directly. Subclasses may override this method to control the drawing of the title.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns YEStrue if the menu item needs to be displayed; otherwise returns NOfalse.

    Declaration

    Swift

    var needsDisplay: Bool

    Objective-C

    @property BOOL needsDisplay

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets whether the menu item needs to be drawn.

    Declaration

    Swift

    var needsDisplay: Bool

    Objective-C

    @property BOOL needsDisplay

    Parameters

    flag

    YEStrue if the menu item needs to be drawn, NOfalse otherwise.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the integer tag of the selected menu item, or 0 if no item is selected.

    Declaration

    Swift

    var tag: Int { get }

    Objective-C

    @property(readonly) NSInteger tag

    Discussion

    Setting the tag value of an NSMenuItemCell object with setTag: does nothing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    See Also

    – setTag: (NSActionCell)