<!--
{
  "documentType" : "article",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/related-ui",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Related UI"
}
-->

# Related UI

Manage contextual menus, cursors, tool tips, and other system-provided windows and content.

## Topics

### Managing Contextual Menus

[`func menu(for: NSEvent) -> NSMenu?`](/documentation/AppKit/NSView/menu(for:))

Overridden by subclasses to return a context-sensitive pop-up menu for a given mouse-down event.

[`class var defaultMenu: NSMenu?`](/documentation/AppKit/NSView/defaultMenu)

Overridden by subclasses to return the default pop-up menu for instances of the receiving class.

[`func willOpenMenu(NSMenu, with: NSEvent)`](/documentation/AppKit/NSView/willOpenMenu(_:with:))

Called just before a contextual menu for a view is opened on screen.

[`func didCloseMenu(NSMenu, with: NSEvent?)`](/documentation/AppKit/NSView/didCloseMenu(_:with:))

Called after a contextual menu that was displayed from the receiving view has been closed.

### Responding to Cursor Movements

[`func addCursorRect(NSRect, cursor: NSCursor)`](/documentation/AppKit/NSView/addCursorRect(_:cursor:))

Establishes  the cursor to be used when the mouse pointer lies within a specified region.

[`func removeCursorRect(NSRect, cursor: NSCursor)`](/documentation/AppKit/NSView/removeCursorRect(_:cursor:))

Completely removes a cursor rectangle from the view.

[`func discardCursorRects()`](/documentation/AppKit/NSView/discardCursorRects())

Invalidates all cursor rectangles set up using [`addCursorRect(_:cursor:)`](/documentation/AppKit/NSView/addCursorRect(_:cursor:)).

[`func resetCursorRects()`](/documentation/AppKit/NSView/resetCursorRects())

Overridden by subclasses to define their default cursor rectangles.

### Providing a Tool Tip

[`var toolTip: String?`](/documentation/AppKit/NSView/toolTip)

The text for the view’s tooltip.

[`func addToolTip(NSRect, owner: Any, userData: UnsafeMutableRawPointer?) -> NSView.ToolTipTag`](/documentation/AppKit/NSView/addToolTip(_:owner:userData:))

Creates a tooltip for a defined area in the view and returns a tag that identifies the tooltip rectangle.

[`func removeAllToolTips()`](/documentation/AppKit/NSView/removeAllToolTips())

Removes all tooltips assigned to the view.

[`func removeToolTip(NSView.ToolTipTag)`](/documentation/AppKit/NSView/removeToolTip(_:))

Removes the tooltip identified by specified tag.

[`typealias ToolTipTag`](/documentation/AppKit/NSView/ToolTipTag)

This type describes the rectangle used to identify a tooltip rectangle.

### Displaying Definition Windows

[`func showDefinition(for: NSAttributedString?, at: NSPoint)`](/documentation/AppKit/NSView/showDefinition(for:at:))

Shows a window displaying the definition of the attributed string at the specified point.

[`func showDefinition(for: NSAttributedString?, range: NSRange, options: [NSView.DefinitionOptionKey : Any]?, baselineOriginProvider: ((NSRange) -> NSPoint)?)`](/documentation/AppKit/NSView/showDefinition(for:range:options:baselineOriginProvider:))

Shows a window displaying the definition of the specified range of the attributed string.

[`struct DefinitionOptionKey`](/documentation/AppKit/NSView/DefinitionOptionKey)

Keys to include in your definition.

[`struct DefinitionPresentationType`](/documentation/AppKit/NSView/DefinitionPresentationType)

Presentation options for the window.

### Getting the Focus View

[`class var focusView: NSView?`](/documentation/AppKit/NSView/focusView)

The currently focused view object.

### Synchronizing with Ruler Views

[`func rulerView(NSRulerView, didAdd: NSRulerMarker)`](/documentation/AppKit/NSView/rulerView(_:didAdd:))

Informs the client that `aRulerView` allowed the user to add `aMarker`.

[`func rulerView(NSRulerView, didMove: NSRulerMarker)`](/documentation/AppKit/NSView/rulerView(_:didMove:))

Informs the client that `aRulerView` allowed the user to move `aMarker`.

[`func rulerView(NSRulerView, didRemove: NSRulerMarker)`](/documentation/AppKit/NSView/rulerView(_:didRemove:))

Informs the client that `aRulerView` allowed the user to remove `aMarker`.

[`func rulerView(NSRulerView, handleMouseDownWith: NSEvent)`](/documentation/AppKit/NSView/rulerView(_:handleMouseDownWith:))

Informs the client that the user has pressed the mouse button while the cursor is in the ruler area of `aRulerView`.

[`func rulerView(NSRulerView, locationFor: NSPoint) -> CGFloat`](/documentation/AppKit/NSView/rulerView(_:locationFor:))

[`func rulerView(NSRulerView, pointForLocation: CGFloat) -> NSPoint`](/documentation/AppKit/NSView/rulerView(_:pointForLocation:))

[`func rulerView(NSRulerView, shouldAdd: NSRulerMarker) -> Bool`](/documentation/AppKit/NSView/rulerView(_:shouldAdd:))

Requests permission for `aRulerView` to add `aMarker`, an NSRulerMarker being dragged onto the ruler by the user.

[`func rulerView(NSRulerView, shouldMove: NSRulerMarker) -> Bool`](/documentation/AppKit/NSView/rulerView(_:shouldMove:))

Requests permission for `aRulerView` to move `aMarker`.

[`func rulerView(NSRulerView, shouldRemove: NSRulerMarker) -> Bool`](/documentation/AppKit/NSView/rulerView(_:shouldRemove:))

Requests permission for `aRulerView` to remove `aMarker`.

[`func rulerView(NSRulerView, willAdd: NSRulerMarker, atLocation: CGFloat) -> CGFloat`](/documentation/AppKit/NSView/rulerView(_:willAdd:atLocation:))

Informs the client that `aRulerView` will add the new NSRulerMarker, `aMarker`.

[`func rulerView(NSRulerView, willMove: NSRulerMarker, toLocation: CGFloat) -> CGFloat`](/documentation/AppKit/NSView/rulerView(_:willMove:toLocation:))

Informs the client that `aRulerView` will move `aMarker`, an NSRulerMarker already on the ruler view.

[`func rulerView(NSRulerView, willSetClientView: NSView)`](/documentation/AppKit/NSView/rulerView(_:willSetClientView:))

Informs the client view that `aRulerView` is about to be appropriated by `newClient`.

### Synchronizing with the display’s refresh rate

[`func displayLink(target: Any, selector: Selector) -> CADisplayLink`](/documentation/AppKit/NSView/displayLink(target:selector:))

Returns a new display link whose callback will be invoked in-sync with the display the view is on.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)