---
title: NSView
framework: appkit
role: symbol
role_heading: Class
path: appkit/nsview
---

# NSView

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

## Declaration

```swift
@MainActor class NSView
```

## Mentioned in

Supporting Writing Tools via the pasteboard Adding Writing Tools support to a custom AppKit view

## Overview

Overview You typically don’t use NSView objects directly. Instead, you use objects that descend from NSView or you subclass NSView yourself and override its methods to implement the behavior you need. An instance of the 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 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 class to support efficient scrolling. AppKit handles most of your app’s NSView management. Unless you’re implementing a concrete subclass of 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 returns the location and size of the NSView object. bounds returns the internal origin and size of the NSView object. needsDisplay determines whether the NSView object needs to be redrawn. window returns the NSWindow object that contains the NSView object. draw(_:) draws the 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() method. For more information on how NSView instances handle event and action messages, see Event Handling. For more information on displaying tooltips and contextual menus, see Displaying Contextual Menus and 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 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 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:) mouseDragged(with:) mouseUp(with:) mouseMoved(with:) mouseEntered(with:) mouseExited(with:) rightMouseDragged(with:) rightMouseUp(with:) otherMouseDown(with:) otherMouseDragged(with:) otherMouseUp(with:) scrollWheel(with:) keyDown(with:) keyUp(with:) flagsChanged(with:) tabletPoint(with:) tabletProximity(with:) note: NSView changes the default behavior of rightMouseDown(with:) so that it calls 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 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:)](appkit/nsview/init(frame:).md)
- [init(coder:)](appkit/nsview/init(coder:).md)
- [prepareForReuse()](appkit/nsview/prepareforreuse().md)

### Configuring the view

- [View Hierarchy](appkit/view-hierarchy.md)
- [View Coordinates](appkit/view-coordinates.md)
- [Appearance](appkit/nsview-appearance.md)
- [Core Animation Support](appkit/core-animation-support.md)
- [Related UI](appkit/related-ui.md)

### Managing the view’s content

- [Layout](appkit/layout.md)
- [Drawing](appkit/nsview-drawing.md)
- [Printing](appkit/nsview-printing.md)
- [NSViewContentSelectionInfo](appkit/nsviewcontentselectioninfo.md)

### Managing interactions

- [Event Handling](appkit/event-handling.md)

### Deprecated

- [Deprecated Symbols](appkit/nsview-deprecated-symbols.md)

### Structures

- [NSView.BoundsDidChangeMessage](appkit/nsview/boundsdidchangemessage.md)
- [NSView.FrameDidChangeMessage](appkit/nsview/framedidchangemessage.md)
- [NSView.LayoutRegion](appkit/nsview/layoutregion.md)

### Instance Properties

- [appEntityUIElementProvider](appkit/nsview/appentityuielementprovider.md)
- [cornerConfiguration](appkit/nsview/cornerconfiguration.md)
- [effectiveCornerRadii](appkit/nsview/effectivecornerradii.md)
- [exclusiveGestureBehavior](appkit/nsview/exclusivegesturebehavior-swift.property.md)
- [prefersCompactControlSizeMetrics](appkit/nsview/preferscompactcontrolsizemetrics.md)
- [textSelectionManager](appkit/nsview/textselectionmanager.md)
- [writingToolsCoordinator](appkit/nsview/writingtoolscoordinator.md)

### Instance Methods

- [edgeInsets(for:)](appkit/nsview/edgeinsets(for:).md)
- [invalidateCornerConfiguration()](appkit/nsview/invalidatecornerconfiguration().md)
- [layoutGuide(for:)](appkit/nsview/layoutguide(for:).md)
- [rect(for:)](appkit/nsview/rect(for:).md)
- [viewDidChangeEffectiveCornerRadii()](appkit/nsview/viewdidchangeeffectivecornerradii().md)

### Enumerations

- [NSView.ExclusiveGestureBehavior](appkit/nsview/exclusivegesturebehavior-swift.enum.md)
- [NSView.Invalidations](appkit/nsview/invalidations.md)

## Relationships

### Inherits From

- [NSResponder](appkit/nsresponder.md)

### Inherited By

- [NSBackgroundExtensionView](appkit/nsbackgroundextensionview.md)
- [NSBox](appkit/nsbox.md)
- [NSClipView](appkit/nsclipview.md)
- [NSCollectionView](appkit/nscollectionview.md)
- [NSControl](appkit/nscontrol.md)
- [NSGlassEffectContainerView](appkit/nsglasseffectcontainerview.md)
- [NSGlassEffectView](appkit/nsglasseffectview.md)
- [NSGridView](appkit/nsgridview.md)
- [NSOpenGLView](appkit/nsopenglview.md)
- [NSProgressIndicator](appkit/nsprogressindicator.md)
- [NSRulerView](appkit/nsrulerview.md)
- [NSScrollView](appkit/nsscrollview.md)
- [NSScrubber](appkit/nsscrubber.md)
- [NSScrubberArrangedView](appkit/nsscrubberarrangedview.md)
- [NSSplitView](appkit/nssplitview.md)
- [NSStackView](appkit/nsstackview.md)
- [NSTabView](appkit/nstabview.md)
- [NSTableCellView](appkit/nstablecellview.md)
- [NSTableHeaderView](appkit/nstableheaderview.md)
- [NSTableRowView](appkit/nstablerowview.md)
- [NSText](appkit/nstext.md)
- [NSTextInsertionIndicator](appkit/nstextinsertionindicator.md)
- [NSVisualEffectView](appkit/nsvisualeffectview.md)

### Conforms To

- [AppEntityAnnotatable](appintents/appentityannotatable.md)
- [CVarArg](swift/cvararg.md)
- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [Hashable](swift/hashable.md)
- [NSAccessibilityElementProtocol](appkit/nsaccessibilityelementprotocol.md)
- [NSAccessibilityProtocol](appkit/nsaccessibilityprotocol.md)
- [NSAnimatablePropertyContainer](appkit/nsanimatablepropertycontainer.md)
- [NSAppearanceCustomization](appkit/nsappearancecustomization.md)
- [NSCoding](foundation/nscoding.md)
- [NSDraggingDestination](appkit/nsdraggingdestination.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSStandardKeyBindingResponding](appkit/nsstandardkeybindingresponding.md)
- [NSTouchBarProvider](appkit/nstouchbarprovider.md)
- [NSUserActivityRestoring](appkit/nsuseractivityrestoring.md)
- [NSUserInterfaceItemIdentification](appkit/nsuserinterfaceitemidentification.md)
- [PlaygroundLiveViewable](playgroundsupport/playgroundliveviewable.md)

## See Also

### View fundamentals

- [NSControl](appkit/nscontrol.md)
- [NSCell](appkit/nscell.md)
- [NSActionCell](appkit/nsactioncell.md)
