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

# NSClipView

An object that clips a document view to a scroll view’s frame.

```
class NSClipView
```

## Overview

An [`NSClipView`](/documentation/AppKit/NSClipView) holds the document view of an [`NSScrollView`](/documentation/AppKit/NSScrollView), clipping the document view to its frame, handling the details of scrolling in an efficient manner, and updating the [`NSScrollView`](/documentation/AppKit/NSScrollView) when the document view’s size or position changes.

You don’t typically use the [`NSClipView`](/documentation/AppKit/NSClipView) class directly; it’s provided primarily as the scrolling machinery for the [`NSScrollView`](/documentation/AppKit/NSScrollView) class. However, you might use the [`NSClipView`](/documentation/AppKit/NSClipView) class to implement a class similar to [`NSScrollView`](/documentation/AppKit/NSScrollView).

### Interaction with NSScrollView

When using an [`NSClipView`](/documentation/AppKit/NSClipView) within an [`NSScrollView`](/documentation/AppKit/NSScrollView) (the usual configuration), you should access the [`NSScrollView`](/documentation/AppKit/NSScrollView) properties that control background drawing state, rather than accessing these properties of the [`NSClipView`](/documentation/AppKit/NSClipView). This recommendation applies to the following properties:

- [`backgroundColor`](/documentation/AppKit/NSClipView/backgroundColor)
- [`drawsBackground`](/documentation/AppKit/NSClipView/drawsBackground)

The [`NSClipView`](/documentation/AppKit/NSClipView) methods are intended for when the [`NSClipView`](/documentation/AppKit/NSClipView) is used independently of a containing [`NSScrollView`](/documentation/AppKit/NSScrollView). In the usual case, [`NSScrollView`](/documentation/AppKit/NSScrollView) should be allowed to manage the background-drawing properties of its associated [`NSClipView`](/documentation/AppKit/NSClipView).

There is only one background-drawing state per [`NSScrollView`](/documentation/AppKit/NSScrollView)/[`NSClipView`](/documentation/AppKit/NSClipView) pair. The two objects do not maintain independent and distinct [`drawsBackground`](/documentation/AppKit/NSClipView/drawsBackground) and [`backgroundColor`](/documentation/AppKit/NSClipView/backgroundColor) properties; rather, the accessors for these properties on [`NSScrollView`](/documentation/AppKit/NSScrollView) largely defer to the associated [`NSClipView`](/documentation/AppKit/NSClipView) and allow the [`NSClipView`](/documentation/AppKit/NSClipView) to maintain the state. Note that this state is not cached by the [`NSScrollView`](/documentation/AppKit/NSScrollView) object.

It is also important to note that setting [`drawsBackground`](/documentation/AppKit/NSClipView/drawsBackground) to <doc://com.apple.documentation/documentation/Swift/false> in an [`NSScrollView`](/documentation/AppKit/NSScrollView) has the added effect of setting the [`NSClipView`](/documentation/AppKit/NSClipView) property [`copiesOnScroll`](/documentation/AppKit/NSClipView/copiesOnScroll) to <doc://com.apple.documentation/documentation/Swift/false>. The side effect of setting the [`drawsBackground`](/documentation/AppKit/NSClipView/drawsBackground) property directly to the [`NSClipView`](/documentation/AppKit/NSClipView) is the appearance of “trails” (vestiges of previous drawing) in the document view as it is scrolled.

## Topics

### Setting the Document View

[`var documentView: NSView?`](/documentation/AppKit/NSClipView/documentView)

The clip view’s document view.

### Scrolling

[`func scroll(to: NSPoint)`](/documentation/AppKit/NSClipView/scroll(to:))

Changes the origin of the clip view’s bounds rectangle to `newOrigin`.

[`func autoscroll(with: NSEvent) -> Bool`](/documentation/AppKit/NSClipView/autoscroll(with:))

Scrolls the clip view proportionally to `theEvent`’s distance outside of it.

[`func constrainScroll(NSPoint) -> NSPoint`](/documentation/AppKit/NSClipView/constrainScroll(_:))

Returns a scroll point adjusted from the proposed new origin, if necessary, to guarantee the view will lie within its document view.

[`func constrainBoundsRect(NSRect) -> NSRect`](/documentation/AppKit/NSClipView/constrainBoundsRect(_:))

Constrains the bounds of the clip view while the user is magnifying and scrolling.

### Determining Scrolling Efficiency

[`var copiesOnScroll: Bool`](/documentation/AppKit/NSClipView/copiesOnScroll)

A Boolean value that indicates if the clip view copies rendered images while scrolling.

### Accessing the Content Insets

[`var contentInsets: NSEdgeInsets`](/documentation/AppKit/NSClipView/contentInsets)

The distance that the content view is inset from the enclosing scroll view.

[`var automaticallyAdjustsContentInsets: Bool`](/documentation/AppKit/NSClipView/automaticallyAdjustsContentInsets)

A Boolean value that indicates if the clip view automatically accounts for other scroll view subviews.

### Accessing the Visible Portion

[`var documentRect: NSRect`](/documentation/AppKit/NSClipView/documentRect)

The rectangle defining the document view’s frame, adjusted to the size of the clip view if the document view is smaller.

[`var documentVisibleRect: NSRect`](/documentation/AppKit/NSClipView/documentVisibleRect)

The exposed rectangle of the clip view’s document view, in the document view’s own coordinate system.

### Setting the Document Cursor

[`var documentCursor: NSCursor?`](/documentation/AppKit/NSClipView/documentCursor)

The cursor object used when the pointer lies over the view.

### Working with Background Color

[`var drawsBackground: Bool`](/documentation/AppKit/NSClipView/drawsBackground)

A Boolean value that indicates if the clip view draws its background color.

[`var backgroundColor: NSColor`](/documentation/AppKit/NSClipView/backgroundColor)

The color of the clip view’s background.

### Overriding NSView Methods

[`func viewBoundsChanged(Notification)`](/documentation/AppKit/NSClipView/viewBoundsChanged(_:))

Handles an [`boundsDidChangeNotification`](/documentation/AppKit/NSView/boundsDidChangeNotification), passed in the `aNotification` argument, by updating a containing [`NSScrollView`](/documentation/AppKit/NSScrollView) based on the new bounds.

[`func viewFrameChanged(Notification)`](/documentation/AppKit/NSClipView/viewFrameChanged(_:))

Handles an [`frameDidChangeNotification`](/documentation/AppKit/NSView/frameDidChangeNotification), passed in the `aNotification` argument, by updating a containing [`NSScrollView`](/documentation/AppKit/NSScrollView) based on the new frame.

## Relationships

### Conforms To

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

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

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

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

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

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

[`Sendable`](/documentation/Swift/Sendable)

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

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

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

[`NSCoding`](/documentation/Foundation/NSCoding)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Equatable`](/documentation/Swift/Equatable)

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

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

[`Hashable`](/documentation/Swift/Hashable)

### Inherits From

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

---

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)