An NSScroller object controls scrolling of a document view within the clip view of an NSScroll​View instance (or potentially of another kind of container view). A scroller displays a slot containing a knob that the user can drag directly to the desired location. The knob indicates both the position within the document view and—by varying in size within the slot—the amount visible relative to the size of the document view.


Prior to OS X v10.7, an NSScroller object can also optionally display scroll buttons. The scroll buttons are a pair of buttons that the user can click to scroll by a small amount (called a line increment or decrement) and Alt-click to scroll by a large amount (called a page increment or decrement).

You normally don’t need to program with scrollers; instead, you typically configure them with an NSScroll​View object in a Nib file.

Don’t use an scroller when a slider would be more appropriate. An NSSlider object represents a range of values for something in the application and lets the user choose a setting. A scroller represents the relative position of the visible portion of a view and lets the user choose which portion to view.


Managing Overlay Style Compatibility

class func is​Compatible​With​Overlay​Scrollers()

Returns a Boolean value that indicates whether the class is compatible with overlay scroller style and behavior.

Determining Scroller Size

class func scroller​Width(for:​ NSControl​Size, scroller​Style:​ NSScroller​Style)

Returns the width for scrollers of the receiving class for a given control size and scroller style.

Laying out a Scroller

var arrows​Position:​ NSScroll​Arrow​Position

The location of the scroll buttons within the scroller, as described in NSScroll​Arrow​Position.

Calculating Layout

func rect(for:​ NSScroller​Part)

Returns the rectangle occupied by a​Part, which for this method is interpreted literally rather than as an indicator of scrolling direction.

func test​Part(NSPoint)

Returns the part that would be hit by a mouse-down event at a​Point (expressed in the window’s coordinate system).

func check​Space​For​Parts()

Checks to see if there is enough room in the receiver to display the knob and buttons.

var usable​Parts:​ NSUsable​Scroller​Parts

A value that indicates which parts of the receiver are displayed and usable.

Drawing Scroller Parts

func draw​Arrow(NSScroller​Arrow, highlight:​ Bool)

Draws the scroll button indicated by arrow, which is either NSScroller​Increment​Arrow (the down or right scroll button) or NSScroller​Decrement​Arrow (up or left).

func draw​Knob​Slot(in:​ NSRect, highlight:​ Bool)

Draws the portion of the scroller’s track, possibly including the line increment and decrement arrow buttons, that falls in the given rectangle.

func draw​Knob()

Draws the knob.

func highlight(Bool)

Highlights or unhighlights the scroll button the user clicked.

Event Handling

var hit​Part:​ NSScroller​Part

A part code indicating the manner in which the scrolling should be performed.

func track​Knob(with:​ NSEvent)

Tracks the knob and sends action messages to the receiver’s target.

func track​Scroll​Buttons(with:​ NSEvent)

Tracks the scroll buttons and sends action messages to the receiver’s target.

Setting Control Tint

var control​Tint:​ NSControl​Tint

The scroller’s control tint.

Managing Presentation Style

class func preferred​Scroller​Style()

Returns the style of scrollers that applications should use wherever possible.

var scroller​Style:​ NSScroller​Style

The scroller style for this scroller.



Constants to specify the scroller style.


Specify different knob styles.


These constants specify the different parts of the scroller:


These constants describe the two scroller buttons and are used by draw​Arrow(_:​highlight:​).


These constants specify where the scroller’s buttons appear and are used by the arrows​Position property.


These constants specify which parts of the scroller are visible.


Instance Properties

var knob​Proportion:​ CGFloat

The proportion of the knob slot that the knob should fill.