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.

Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.
  • menuItem menuItem Property

    The menu item object associated with the cell.

    Declaration

    Swift

    var menuItem: NSMenuItem?

    Objective-C

    @property(strong) NSMenuItem *menuItem

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the menu view associated with the receiver.

    Declaration

    Objective-C

    - (NSMenuView *)menuView

    Import Statement

    Objective-C

    @import AppKit;

    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

    Objective-C

    @import AppKit;

    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

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    needsSizing

  • A Boolean value indicating whether the size of the menu needs to be calculated.

    Declaration

    Swift

    var needsSizing: Bool

    Objective-C

    @property BOOL needsSizing

    Discussion

    When the value of this property is YEStrue, the next attempt to obtain size information about the menu cause the calcSize method to be called. When the value of the property is NOfalse, the size information is obtained from the currently cached values.

    Subclasses that drastically change the way a menu item is drawn can change the value of this property to update the menu item information. Other parts of your application should not need to change this property directly. The cell checks this value of this property as necessary when the content of its menu item changes.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – calcSize

  • The width of the image associated with the menu item. (read-only)

    Declaration

    Swift

    var imageWidth: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat imageWidth

    Discussion

    The width of the image is measured in points. You can associate an image with a menu item using the setImage: method of NSMenuItem.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • The width of the menu item’s text, measured in points. (read-only)

    Declaration

    Swift

    var titleWidth: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat titleWidth

    Discussion

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • The width of the menu item’s key equivalent string. (read-only)

    Declaration

    Swift

    var keyEquivalentWidth: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat keyEquivalentWidth

    Discussion

    To set the menu item’s key equivalent, use the keyEquivalent property of NSMenuItem.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • The width of the image used to indicate the state of the menu item. (read-only)

    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 property contains the width of the largest image. You can set the state images for a menu item using the setOnStateImage:, setOffStateImage:, and setMixedStateImage: methods of NSMenuItem.

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    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

    Objective-C

    @import AppKit;

    Swift

    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

    Objective-C

    @import AppKit;

    Swift

    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

    Objective-C

    @import AppKit;

    Swift

    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

    Objective-C

    @import AppKit;

    Swift

    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

    Objective-C

    @import AppKit;

    Swift

    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

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • A Boolean value indicating whether the menu item needs to be displayed.

    Declaration

    Swift

    var needsDisplay: Bool

    Objective-C

    @property BOOL needsDisplay

    Discussion

    Set this property to YEStrue when you want the menu item to be drawn.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • tag tag Property

    The integer tag of the selected menu item. (read-only)

    Declaration

    Swift

    var tag: Int { get }

    Objective-C

    @property(readonly) NSInteger tag

    Discussion

    If no item is selected, the value in this property is 0.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    See Also

    – setTag: (NSActionCell)