A slider is a UI element that displays a range of values in the app. Sliders can be vertical or horizontal bars or circular dials. An indicator, or knob, notes the current setting. The user can move the knob in the slider’s bar—or rotate the knob in a circular slider—to change the setting.


The NSSlider class uses the NSSliderCell class to implement its user interface.


Creating Sliders

init(target: Any?, action: Selector?)

Creates and returns a continuous horizontal slider whose values range from 0.0 to 1.0.

init(value: Double, minValue: Double, maxValue: Double, target: Any?, action: Selector?)

Creates and returns a continuous horizontal slider that represents values over the specified range.

Managing the Slider’s Appearance

var sliderType: NSSliderType

The type of the slider, such as vertical or circular.

var altIncrementValue: Double

The amount by which the receiver changes its value when the user Option-drags the slider knob.

var knobThickness: CGFloat

The knob’s thickness, in pixels.

var isVertical: Bool

An integer indicating the orientation (horizontal or vertical) of the slider.

Asking About the Value Limits

var maxValue: Double

The maximum value the receiver can send to its target.

var minValue: Double

The minimum value the receiver can send to its target.

Handling Mouse-Down Events

func acceptsFirstMouse(for: NSEvent?)

Returns a Boolean value indicating whether the slider accepts a single mouse-down event that simultaneously activates the window and takes hold of the slider’s knob.

Managing Tick Marks

var allowsTickMarkValuesOnly: Bool

A Boolean value that indicates whether the receiver fixes its values to those values represented by its tick marks.

func closestTickMarkValue(toValue: Double)

Returns the value of the tick mark closest to the specified value.

func indexOfTickMark(at: NSPoint)

Returns the index of the tick mark closest to the location of the receiver represented by the given point.

var numberOfTickMarks: Int

The number of tick marks associated with the receiver.

func rectOfTickMark(at: Int)

Returns the bounding rectangle of the tick mark at the given index.

var tickMarkPosition: NSTickMarkPosition

Determines how the receiver’s tick marks are aligned with it.

func tickMarkValue(at: Int)

Returns the receiver’s value represented by the tick mark at the specified index.


Inherits From