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

# NSScrollView

A view that displays a portion of a document view and provides scroll bars that allow the user to move the document view within the scroll view.

```
class NSScrollView
```

## Overview

The [`NSScrollView`](/documentation/AppKit/NSScrollView) class is the central coordinator for AppKit’s scrolling machinery, which is composed of this class, and the [`NSClipView`](/documentation/AppKit/NSClipView) and [`NSScroller`](/documentation/AppKit/NSScroller) classes.

When using an [`NSClipView`](/documentation/AppKit/NSClipView) object within a scroll view (the usual configuration), you should issue messages that control background drawing state to the scroll view directly, rather than messaging the clip view.

### Touch scrolling

[`NSScrollView`](/documentation/AppKit/NSScrollView) supports pull-to-refresh functionality. Assign an [`NSRefreshController`](/documentation/AppKit/NSRefreshController) to its [`refreshController`](/documentation/AppKit/NSScrollView/refreshController) property, and it initiates your target and action when someone pulls down past the top of the scrollable area.

By default, a single touch scrolls the view. If your content also needs to respond to single-touch gestures of its own — such as drawing or marking up a map — set [`minimumNumberOfTouchesForScrolling`](/documentation/AppKit/NSScrollView/minimumNumberOfTouchesForScrolling) to a higher value, such as `2`, so a single touch stays free for your own gesture recognizers and only multiple touches scroll the view. Use [`maximumNumberOfTouchesForScrolling`](/documentation/AppKit/NSScrollView/maximumNumberOfTouchesForScrolling) alongside it to limit how many touches scrolling accepts. Set [`isTouchScrollingEnabled`](/documentation/AppKit/NSScrollView/isTouchScrollingEnabled) to `false` to turn off touch scrolling entirely, such as when your content already handles single-touch panning itself.

If your own gesture recognizers compete with the scroll view’s built-in scrolling and magnification gestures, use [`scrollGestureForRelationships`](/documentation/AppKit/NSScrollView/scrollGestureForRelationships) to set up failure or exclusion relationships against them. For more information, see [Prioritize gesture recognizers](/documentation/AppKit/handling-appkit-gestures#Prioritize-gesture-recognizers).

[`minimumNumberOfTouches`](/documentation/AppKit/NSPanGestureRecognizer/minimumNumberOfTouches) and [`maximumNumberOfTouches`](/documentation/AppKit/NSPanGestureRecognizer/maximumNumberOfTouches) replace [`numberOfTouchesRequired`](/documentation/AppKit/NSPanGestureRecognizer/numberOfTouchesRequired), which is deprecated. Set [`maximumNumberOfTouches`](/documentation/AppKit/NSPanGestureRecognizer/maximumNumberOfTouches) to `0` to require exactly [`minimumNumberOfTouches`](/documentation/AppKit/NSPanGestureRecognizer/minimumNumberOfTouches) touches; it defaults to `NSIntegerMax`.

For more information, see [Adopting gesture recognizers in your app](/documentation/AppKit/adopting-gesture-recognizers-in-your-app).

## Topics

### Creating a scroll view

[`init?(coder: NSCoder)`](/documentation/AppKit/NSScrollView/init(coder:))

[`init(frame: NSRect)`](/documentation/AppKit/NSScrollView/init(frame:))

### Calculating layout

[`class func frameSize(forContentSize: NSSize, horizontalScrollerClass: AnyClass?, verticalScrollerClass: AnyClass?, borderType: NSBorderType, controlSize: NSControl.ControlSize, scrollerStyle: NSScroller.Style) -> NSSize`](/documentation/AppKit/NSScrollView/frameSize(forContentSize:horizontalScrollerClass:verticalScrollerClass:borderType:controlSize:scrollerStyle:))

Returns the frame size of a scroll view that contains a content view with the specified size.

[`class func contentSize(forFrameSize: NSSize, horizontalScrollerClass: AnyClass?, verticalScrollerClass: AnyClass?, borderType: NSBorderType, controlSize: NSControl.ControlSize, scrollerStyle: NSScroller.Style) -> NSSize`](/documentation/AppKit/NSScrollView/contentSize(forFrameSize:horizontalScrollerClass:verticalScrollerClass:borderType:controlSize:scrollerStyle:))

Returns the content size calculated from the frame size and the specified specifications.

[`+ (NSSize) frameSizeForContentSize:(NSSize) cSize hasHorizontalScroller:(BOOL) hFlag hasVerticalScroller:(BOOL) vFlag borderType:(NSBorderType) type;`](/documentation/AppKit/NSScrollView/frameSizeForContentSize:hasHorizontalScroller:hasVerticalScroller:borderType:)

Returns the frame size of an scroll view that contains a content view with the specified size.

[`+ (NSSize) contentSizeForFrameSize:(NSSize) fSize hasHorizontalScroller:(BOOL) hFlag hasVerticalScroller:(BOOL) vFlag borderType:(NSBorderType) type;`](/documentation/AppKit/NSScrollView/contentSizeForFrameSize:hasHorizontalScroller:hasVerticalScroller:borderType:)

Returns the content size calculated from the frame size and the specified specifications.

### Determining component sizes

[`var contentSize: NSSize`](/documentation/AppKit/NSScrollView/contentSize)

The size of the scroll view’s content view.

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

The portion of the document view, in its own coordinate system, visible through the scroll view’s content view.

### Managing graphics attributes

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

The color of the content view’s background.

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

A Boolean that indicates whether the scroll view draws its background.

[`var borderType: NSBorderType`](/documentation/AppKit/NSScrollView/borderType)

A value that specifies the appearance of the scroll view’s border.

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

The content view’s document cursor.

### Managing the views

[`var contentView: NSClipView`](/documentation/AppKit/NSScrollView/contentView)

The scroll view’s content view, the view that clips the document view.

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

The view the scroll view scrolls within its content view.

[`func addFloatingSubview(NSView, for: NSEvent.GestureAxis)`](/documentation/AppKit/NSScrollView/addFloatingSubview(_:for:))

Adds a floating subview to the document view.

### Managing scrollers

[`var horizontalScroller: NSScroller?`](/documentation/AppKit/NSScrollView/horizontalScroller)

The scroll view’s horizontal scroller.

[`var hasHorizontalScroller: Bool`](/documentation/AppKit/NSScrollView/hasHorizontalScroller)

A Boolean that indicates whether the scroll view has a horizontal scroller.

[`var verticalScroller: NSScroller?`](/documentation/AppKit/NSScrollView/verticalScroller)

The scroll view’s vertical scroller.

[`var hasVerticalScroller: Bool`](/documentation/AppKit/NSScrollView/hasVerticalScroller)

A Boolean that indicates whether the scroll view has a vertical scroller.

[`var autohidesScrollers: Bool`](/documentation/AppKit/NSScrollView/autohidesScrollers)

A Boolean that indicates whether the scroll view automatically hides its scroll bars when they are not needed.

### Managing rulers

[`class var rulerViewClass: AnyClass!`](/documentation/AppKit/NSScrollView/rulerViewClass)

Returns the default class to be used for ruler objects in NSScrollViews.

[`var hasHorizontalRuler: Bool`](/documentation/AppKit/NSScrollView/hasHorizontalRuler)

A Boolean that indicates whether the scroll view keeps a horizontal ruler object.

[`var horizontalRulerView: NSRulerView?`](/documentation/AppKit/NSScrollView/horizontalRulerView)

The scroll view’s horizontal ruler view.

[`var hasVerticalRuler: Bool`](/documentation/AppKit/NSScrollView/hasVerticalRuler)

A Boolean that indicates whether the scroll view keeps a vertical ruler object.

[`var verticalRulerView: NSRulerView?`](/documentation/AppKit/NSScrollView/verticalRulerView)

The scroll view’s vertical ruler view.

[`var rulersVisible: Bool`](/documentation/AppKit/NSScrollView/rulersVisible)

A Boolean that indicates whether the scroll view displays its rulers.

### Managing insets

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

A Boolean that indicates whether the scroll view automatically adjusts its content insets.

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

The distance that the scroll view’s subviews are inset from the enclosing scroll view during tiling.

[`var scrollerInsets: NSEdgeInsets`](/documentation/AppKit/NSScrollView/scrollerInsets)

The distance the scrollers are inset from the edge of the scroll view.

### Scroller style

[`var scrollerKnobStyle: NSScroller.KnobStyle`](/documentation/AppKit/NSScrollView/scrollerKnobStyle)

The knob style of scroll views that use the overlay scroller style.

[`var scrollerStyle: NSScroller.Style`](/documentation/AppKit/NSScrollView/scrollerStyle)

The scroller style used by the scroll view.

### Setting scrolling behavior

[`var lineScroll: CGFloat`](/documentation/AppKit/NSScrollView/lineScroll)

The scroll view’s line by line scroll amount.

[`var horizontalLineScroll: CGFloat`](/documentation/AppKit/NSScrollView/horizontalLineScroll)

The scroll view’s horizontal line by line scroll amount.

[`var verticalLineScroll: CGFloat`](/documentation/AppKit/NSScrollView/verticalLineScroll)

The scroll view’s vertical line by line scroll amount.

[`var pageScroll: CGFloat`](/documentation/AppKit/NSScrollView/pageScroll)

The amount of the document view kept visible when scrolling page by page.

[`var horizontalPageScroll: CGFloat`](/documentation/AppKit/NSScrollView/horizontalPageScroll)

The amount of the document view kept visible when scrolling horizontally page by page.

[`var verticalPageScroll: CGFloat`](/documentation/AppKit/NSScrollView/verticalPageScroll)

The amount of the document view kept visible when scrolling vertically page by page.

[`var scrollsDynamically: Bool`](/documentation/AppKit/NSScrollView/scrollsDynamically)

A Boolean that indicates whether the scroll view redraws its document view while scrolling continuously.

[`func scrollWheel(with: NSEvent)`](/documentation/AppKit/NSScrollView/scrollWheel(with:))

Scrolls the receiver up or down, in response to the user moving the mouse’s scroll wheel specified by `theEvent`.

### Configuring touch scrolling

[`var isTouchScrollingEnabled: Bool`](/documentation/AppKit/NSScrollView/isTouchScrollingEnabled)

Enable touch scrolling

[`var minimumNumberOfTouchesForScrolling: Int`](/documentation/AppKit/NSScrollView/minimumNumberOfTouchesForScrolling)

The minimum number of touches needed for scrolling

[`var maximumNumberOfTouchesForScrolling: Int`](/documentation/AppKit/NSScrollView/maximumNumberOfTouchesForScrolling)

The maximum number of touches needed for scrolling

[`var scrollGestureForRelationships: NSGestureRecognizer`](/documentation/AppKit/NSScrollView/scrollGestureForRelationships)

A gesture recognizer for setting up failure or exclusion relationships against scrolling gestures

[`var refreshController: NSRefreshController?`](/documentation/AppKit/NSScrollView/refreshController)

The refresh controller associated with this scroll view.

### Updating display after scrolling

[`func reflectScrolledClipView(NSClipView)`](/documentation/AppKit/NSScrollView/reflectScrolledClipView(_:))

Adjusts the receiver’s scrollers to reflect the size and positioning of its content view.

### Arranging components

[`func tile()`](/documentation/AppKit/NSScrollView/tile())

Lays out the components of the receiver: the content view, the scrollers, and the ruler views.

### Find bar positioning

[`var findBarPosition: NSScrollView.FindBarPosition`](/documentation/AppKit/NSScrollView/findBarPosition-swift.property)

The position of the find bar.

[`enum FindBarPosition`](/documentation/AppKit/NSScrollView/FindBarPosition-swift.enum)

These constants define the position of the find bar in relation to the scroll view.

### Specifying a document’s predominant scrolling behavior

[`var usesPredominantAxisScrolling: Bool`](/documentation/AppKit/NSScrollView/usesPredominantAxisScrolling)

A Boolean that indicates whether the scroll view uses a predominant scrolling axis for content.

### Specifying the scroll view elasticity

[`var horizontalScrollElasticity: NSScrollView.Elasticity`](/documentation/AppKit/NSScrollView/horizontalScrollElasticity)

The scroll view’s horizontal scrolling elasticity mode.

[`var verticalScrollElasticity: NSScrollView.Elasticity`](/documentation/AppKit/NSScrollView/verticalScrollElasticity)

The scroll view’s vertical scrolling elasticity mode.

[`enum Elasticity`](/documentation/AppKit/NSScrollView/Elasticity)

These constants determine the elasticity behavior for an axis of the scrollview.

### Flashing overlay scroll bars

[`func flashScrollers()`](/documentation/AppKit/NSScrollView/flashScrollers())

Flash the overlay scroll bars.

### Zooming the scroll view

[`var allowsMagnification: Bool`](/documentation/AppKit/NSScrollView/allowsMagnification)

Allows the user to magnify the scroll view.

[`var magnification: CGFloat`](/documentation/AppKit/NSScrollView/magnification)

The amount by which the content is currently scaled.

[`func magnify(toFit: NSRect)`](/documentation/AppKit/NSScrollView/magnify(toFit:))

Magnifies the content view proportionally such that the given rectangle fits centered in the scroll view.

[`var maxMagnification: CGFloat`](/documentation/AppKit/NSScrollView/maxMagnification)

The maximum value to which the content can be magnified.

[`var minMagnification: CGFloat`](/documentation/AppKit/NSScrollView/minMagnification)

The minimum value to which the content can be magnified.

[`func setMagnification(CGFloat, centeredAt: NSPoint)`](/documentation/AppKit/NSScrollView/setMagnification(_:centeredAt:))

Magnify the content by the given amount and center the result on the given point.

### Notifications

[`class let willStartLiveMagnifyNotification: NSNotification.Name`](/documentation/AppKit/NSScrollView/willStartLiveMagnifyNotification)

Posted at the beginning of a magnify gesture.

[`struct WillStartLiveMagnifyMessage`](/documentation/AppKit/NSScrollView/WillStartLiveMagnifyMessage)

[`class let didEndLiveMagnifyNotification: NSNotification.Name`](/documentation/AppKit/NSScrollView/didEndLiveMagnifyNotification)

Posted at the end of a magnify gesture.

[`struct DidEndLiveMagnifyMessage`](/documentation/AppKit/NSScrollView/DidEndLiveMagnifyMessage)

[`class let willStartLiveScrollNotification: NSNotification.Name`](/documentation/AppKit/NSScrollView/willStartLiveScrollNotification)

Posted on the main thread at the beginning of user-initiated live scroll tracking (gesture scroll or scroller tracking, for example, thumb dragging).

[`struct WillStartLiveScrollMessage`](/documentation/AppKit/NSScrollView/WillStartLiveScrollMessage)

[`class let didLiveScrollNotification: NSNotification.Name`](/documentation/AppKit/NSScrollView/didLiveScrollNotification)

Posted on the main thread after changing the clipview bounds origin due to a user-initiated event.

[`struct DidLiveScrollMessage`](/documentation/AppKit/NSScrollView/DidLiveScrollMessage)

[`class let didEndLiveScrollNotification: NSNotification.Name`](/documentation/AppKit/NSScrollView/didEndLiveScrollNotification)

Posted on the main thread at the end of live scroll tracking.

[`struct DidEndLiveScrollMessage`](/documentation/AppKit/NSScrollView/DidEndLiveScrollMessage)

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

### 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)