<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSView",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSView"
  },
  "title" : "NSView"
}
-->

# NSView

The infrastructure for drawing, printing, and handling events in an app.

```
@MainActor class NSView
```

## Overview

You typically don’t use [`NSView`](/documentation/AppKit/NSView) objects directly. Instead, you use objects that descend from [`NSView`](/documentation/AppKit/NSView) or you subclass [`NSView`](/documentation/AppKit/NSView) yourself and override its methods to implement the behavior you need. An instance of the [`NSView`](/documentation/AppKit/NSView) class (or one of its subclasses) is commonly known as a view object, or simply as a view.

Views handle the presentation and interaction with your app’s visible content. You arrange one or more views inside an [`NSWindow`](/documentation/AppKit/NSWindow) object, which acts as a wrapper for your content. A view object defines a rectangular region for drawing and receiving mouse events. Views handle other chores as well, including the dragging of icons and working with the [`NSScrollView`](/documentation/AppKit/NSScrollView) class to support efficient scrolling.

AppKit handles most of your app’s [`NSView`](/documentation/AppKit/NSView) management. Unless you’re implementing a concrete subclass of [`NSView`](/documentation/AppKit/NSView) or working intimately with the content of the view hierarchy at runtime, you don’t need to know much about this class’s interface. For any view, there are many methods that you can use as-is. The following methods are commonly used.

- [`frame`](/documentation/AppKit/NSView/frame) returns the location and size of the [`NSView`](/documentation/AppKit/NSView) object.
- [`bounds`](/documentation/AppKit/NSView/bounds) returns the internal origin and size of the [`NSView`](/documentation/AppKit/NSView) object.
- [`needsDisplay`](/documentation/AppKit/NSView/needsDisplay) determines whether the [`NSView`](/documentation/AppKit/NSView) object needs to be redrawn.
- [`window`](/documentation/AppKit/NSView/window) returns the [`NSWindow`](/documentation/AppKit/NSWindow) object that contains the [`NSView`](/documentation/AppKit/NSView) object.
- [`draw(_:)`](/documentation/AppKit/NSView/draw(_:)) draws the [`NSView`](/documentation/AppKit/NSView) object. (All subclasses must implement this method, but it’s rarely invoked explicitly.) An alternative to drawing is to update the layer directly using the [`updateLayer()`](/documentation/AppKit/NSView/updateLayer()) method.

For more information on how `NSView` instances handle event and action messages, see [Event Handling](/documentation/AppKit/event-handling). For more information on displaying tooltips and contextual menus, see [`Displaying Contextual Menus`](/documentation/AppKit/NSMenu#Displaying-Contextual-Menus) and [`Managing Tooltips`](/documentation/AppKit/NSWindow#Managing-Tooltips).

### Subclassing notes

`NSView` is perhaps the most important class in AppKit when it comes to subclassing and inheritance. Most user-interface objects you see in a Cocoa application are objects that inherit from `NSView`. If you want to create an object that draws itself in a special way, or that responds to mouse clicks in a special way, you would create a custom subclass of `NSView` (or of a class that inherits from `NSView`).

#### Handling events in your subclass

If you subclass [`NSView`](/documentation/AppKit/NSView) directly and handle specific types of events, don’t call `super` in the implementations of your event-related methods. Views inherit their event-handling capabilities from their [`NSResponder`](/documentation/AppKit/NSResponder) parent class. The default behavior for responders is to pass events up the responder chain, which isn’t the behavior you typically want for a custom view. Therefore, don’t call `super` if your view implements any of the following methods and handles the event:

- [`mouseDown(with:)`](/documentation/AppKit/NSResponder/mouseDown(with:))
- [`mouseDragged(with:)`](/documentation/AppKit/NSResponder/mouseDragged(with:))
- [`mouseUp(with:)`](/documentation/AppKit/NSResponder/mouseUp(with:))
- [`mouseMoved(with:)`](/documentation/AppKit/NSResponder/mouseMoved(with:))
- [`mouseEntered(with:)`](/documentation/AppKit/NSResponder/mouseEntered(with:))
- [`mouseExited(with:)`](/documentation/AppKit/NSResponder/mouseExited(with:))
- [`rightMouseDragged(with:)`](/documentation/AppKit/NSResponder/rightMouseDragged(with:))
- [`rightMouseUp(with:)`](/documentation/AppKit/NSResponder/rightMouseUp(with:))
- [`otherMouseDown(with:)`](/documentation/AppKit/NSResponder/otherMouseDown(with:))
- [`otherMouseDragged(with:)`](/documentation/AppKit/NSResponder/otherMouseDragged(with:))
- [`otherMouseUp(with:)`](/documentation/AppKit/NSResponder/otherMouseUp(with:))
- [`scrollWheel(with:)`](/documentation/AppKit/NSResponder/scrollWheel(with:))
- [`keyDown(with:)`](/documentation/AppKit/NSResponder/keyDown(with:))
- [`keyUp(with:)`](/documentation/AppKit/NSResponder/keyUp(with:))
- [`flagsChanged(with:)`](/documentation/AppKit/NSResponder/flagsChanged(with:))
- [`tabletPoint(with:)`](/documentation/AppKit/NSResponder/tabletPoint(with:))
- [`tabletProximity(with:)`](/documentation/AppKit/NSResponder/tabletProximity(with:))

> Note:
> `NSView` changes the default behavior of ``doc://com.apple.appkit/documentation/AppKit/NSResponder/rightMouseDown(with:)`` so that it calls ``doc://com.apple.appkit/documentation/AppKit/NSView/menu(for:)`` and, if non `nil`, presents the contextual menu. In macOS 10.7 and later, if the event is not handled, `NSView` passes the event up the responder chain. Because of these behaviorial changes, call `super` when implementing ``doc://com.apple.appkit/documentation/AppKit/NSResponder/rightMouseDown(with:)`` in your custom `NSView` subclasses.

If your view descends from a class other than `NSView`, call `super` to let the parent view handle any events that you don’t.

## Topics

### Creating a view object

[`init(frame:)`](/documentation/AppKit/NSView/init(frame:))

Initializes and returns a newly allocated `NSView` object with a specified frame rectangle.

[`init(coder:)`](/documentation/AppKit/NSView/init(coder:))

Initializes a view using from data in the specified coder object.

[`prepareForReuse()`](/documentation/AppKit/NSView/prepareForReuse())

Restores the view to an initial state so that it can be reused.

### Configuring the view

[View Hierarchy](/documentation/AppKit/view-hierarchy)

Manage the subviews, superview, and window of a view and respond to notifications when the view hierarchy changes.

[View Coordinates](/documentation/AppKit/view-coordinates)

Manage the frame and bounds rectangles that determine the size and position of the view in the view hierarchy.

[Appearance](/documentation/AppKit/nsview-appearance)

Change the view’s visibility, vibrancy, and focus ring and respond to appearance-related changes.

[Core Animation Support](/documentation/AppKit/core-animation-support)

Manage the layer object that provides the view’s visual representation and accelerates drawing operations.

[Related UI](/documentation/AppKit/related-ui)

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

### Managing the view’s content

[Layout](/documentation/AppKit/layout)

Specify the size and position your view relative to other nearby views using rules that update your view hierarchy automatically.

[Drawing](/documentation/AppKit/nsview-drawing)

Draw the content of custom views and update that content when the view’s size or appearance changes.

[Printing](/documentation/AppKit/nsview-printing)

Create a printable version of your view’s content and handle pagination and printer-related behaviors.

[`NSViewContentSelectionInfo`](/documentation/AppKit/NSViewContentSelectionInfo)

### Managing interactions

[Event Handling](/documentation/AppKit/event-handling)

Respond to mouse, keyboard, touch, and tablet events and gestures that originate inside your view.

### Observing bounds and frame changes

[`NSView.BoundsDidChangeMessage`](/documentation/AppKit/NSView/BoundsDidChangeMessage)

[`NSView.FrameDidChangeMessage`](/documentation/AppKit/NSView/FrameDidChangeMessage)

### Detecting content for Apple Intelligence and Siri

[`appEntityUIElementProvider`](/documentation/AppKit/NSView/appEntityUIElementProvider)

A closure that provides app entity identifiers to make custom view content discoverable by Apple Intelligence
and Siri when it appears onscreen.

### Configuring corners

[`cornerConfiguration`](/documentation/AppKit/NSView/cornerConfiguration)

Defines the corner styles (e.g., square, capsule, concentric, etc) for the view’s corners.

[`effectiveCornerRadii`](/documentation/AppKit/NSView/effectiveCornerRadii)

The effective radius of each corner in the view, calculated based on the corner configuration (`cornerConfiguration`). This value is `nil` when the corner configuration is `nil`.

[`invalidateCornerConfiguration()`](/documentation/AppKit/NSView/invalidateCornerConfiguration())

Invalidates the corner configuration, causing both the configuration and its dependencies to be recomputed.

[`viewDidChangeEffectiveCornerRadii()`](/documentation/AppKit/NSView/viewDidChangeEffectiveCornerRadii())

Informs the view that its effective corner radii changed. This method should be overridden to apply the corner radii to the view as required.

### Managing text selection

[`textSelectionManager`](/documentation/AppKit/NSView/textSelectionManager)

The text selection manager for this view.

### Supporting writing tools

[`writingToolsCoordinator`](/documentation/AppKit/NSView/writingToolsCoordinator)

### Getting layout regions

[`NSView.LayoutRegion`](/documentation/AppKit/NSView/LayoutRegion)

[`edgeInsets(for:)`](/documentation/AppKit/NSView/edgeInsets(for:))

[`layoutGuide(for:)`](/documentation/AppKit/NSView/layoutGuide(for:))

[`rect(for:)`](/documentation/AppKit/NSView/rect(for:))

### Adopting compact control metrics

[`prefersCompactControlSizeMetrics`](/documentation/AppKit/NSView/prefersCompactControlSizeMetrics)

When this property is `YES`, any `NSControl`s in the view or its descendants will be sized with compact metrics compatible with macOS 15.0 and earlier.
Defaults to `NO`.

### Managing gesture exclusivity

[`exclusiveGestureBehavior`](/documentation/AppKit/NSView/exclusiveGestureBehavior-swift.property)

Declares whether gesture recognizers should be exclusive in this view and its subviews.

[`NSView.ExclusiveGestureBehavior`](/documentation/AppKit/NSView/ExclusiveGestureBehavior-swift.enum)

Exclusive gesture behavior

### Invalidating view state

[`NSView.Invalidations`](/documentation/AppKit/NSView/Invalidations)

Changes that cause aspects of a view to be invalid and require an update.

### Deprecated

[Deprecated Symbols](/documentation/AppKit/nsview-deprecated-symbols)

Review unsupported symbols and their replacements.



---

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)