Mac Developer Library

Developer

AppKit Framework Reference NSSlider Class Reference

Options
Deployment Target:

On This Page
Language:

NSSlider

An NSSlider object displays a range of values for something in the application. 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. More...

Import Statement


import AppKit @import AppKit;

Availability


Available in OS X v10.0 and later.
  • Returns the amount by which the receiver changes its value when the user Option–drags the slider knob.

    Declaration

    Swift

    var altIncrementValue: Double

    Objective-C

    @property double altIncrementValue

    Return Value

    The amount by which the value changes when the user drags the slider knob with the Option key held down. Unless you call setAltIncrementValue:, altIncrementValue returns –1.0, and the receiver behaves no differently with the Option key down than with it up.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • image image (OS X v10.9)

    This method has been deprecated. Returns nil.

    Declaration

    Objective-C

    - (NSImage *)image

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.9.

    See Also

    – setImage:

  • Returns the knob’s thickness, in pixels.

    Declaration

    Swift

    var knobThickness: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat knobThickness

    Return Value

    The thickness of the slider knob. The thickness is defined to be the extent of the knob along the long dimension of the bar. In a vertical slider, then, a knob’s thickness is its height; in a horizontal slider, a knob’s thickness is its width.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • isVertical isVertical Available in OS X v10.0 through OS X v10.9

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

    Declaration

    Objective-C

    - (NSInteger)isVertical

    Return Value

    1 if the receiver is vertical, 0 if it’s horizontal, and –1 if the orientation can’t be determined (for example, if the slider hasn’t been displayed yet). A slider is defined as vertical if its height is greater than its width.

    Import Statement

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Sets the amount by which the NSSliderCell modifies its value when the user Option-drags the knob.

    Declaration

    Swift

    var altIncrementValue: Double

    Objective-C

    @property double altIncrementValue

    Parameters

    increment

    The amount by which the slider's value changes when the user Option–drags its knob. This value must fit the range of values the slider can represent—for example, if the slider has a minimum value of 5 and a maximum value of 10, increment should be between 0 and 5. If increment is outside that range, the value is unchanged.

    Discussion

    If you don’t call this method, the slider behaves the same with the Option key down as with it up. This is also the result when you call setAltIncrementValue: with an increment of –1.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • setImage: setImage: (OS X v10.9)

    This method has been deprecated. Sets the image the receiver displays in the bar behind its knob.

    Declaration

    Objective-C

    - (void)setImage:(NSImage *)barImage

    Parameters

    barImage

    The image to set.

    Discussion

    The slider may scale and distort barImage to fit inside the bar.

    The knob may cover part of the image. If you want the image to be visible all the time, you’re better off placing it near the slider.

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.9.

    See Also

    – setImage:

  • This method has been deprecated. Lets you set the knob’s thickness, measured in pixels.

    Declaration

    Objective-C

    - (void)setKnobThickness:(CGFloat)thickness

    Parameters

    thickness

    The thickness of the knob. The thickness is defined to be the extent of the knob along the long dimension of the bar. In a vertical slider, a knob’s thickness is its height; in a horizontal slider, a knob’s thickness is its width.

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.9.

  • title title (OS X v10.9)

    Returns the receiver’s title.

    Declaration

    Objective-C

    - (NSString *)title

    Return Value

    The title. The default title is the empty string (@"").

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.9.

    See Also

    – setTitle:

  • titleCell titleCell (OS X v10.9)

    This method has been deprecated. Returns nil.

    Declaration

    Objective-C

    - (id)titleCell

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.9.

  • titleColor titleColor (OS X v10.9)

    This method has been deprecated. Returns nil.

    Declaration

    Objective-C

    - (NSColor *)titleColor

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.9.

  • titleFont titleFont (OS X v10.9)

    This method has been deprecated. Returns nil.

    Declaration

    Objective-C

    - (NSFont *)titleFont

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.9.

  • setTitle: setTitle: (OS X v10.9)

    This method has been deprecated. Sets the title the receiver displays in the bar behind its knob.

    Declaration

    Objective-C

    - (void)setTitle:(NSString *)barTitle

    Parameters

    barTitle

    The slider's title. The knob may cover part or all of the title. If you want the title to be visible all the time, you’re better off placing a label near the slider.

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.9.

    See Also

    – title

  • This method has been deprecated. Sets the cell used to draw the receiver’s title.

    Declaration

    Objective-C

    - (void)setTitleCell:(NSCell *)titleCell

    Parameters

    titleCell

    The cell used to draw the title.

    Discussion

    You only need to invoke this method if the default title cell, NSTextFieldCell, doesn’t suit your needs—that is, you want to display the title in a manner that NSTextFieldCell doesn’t permit. When you do choose to override the default, titleCell should be an instance of a subclass of NSTextFieldCell.

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.9.

    See Also

    – titleCell

  • This method has been deprecated. Sets the color used to draw the receiver’s title.

    Declaration

    Objective-C

    - (void)setTitleColor:(NSColor *)color

    Parameters

    color

    The title color.

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.9.

    See Also

    – titleColor

  • This method has been deprecated. Sets the font used to draw the receiver’s title.

    Declaration

    Objective-C

    - (void)setTitleFont:(NSFont *)font

    Parameters

    font

    The title font.

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.9.

    See Also

    – titleFont

  • Returns the maximum value the receiver can send to its target.

    Declaration

    Swift

    var maxValue: Double

    Objective-C

    @property double maxValue

    Return Value

    The slider's maximum value. A horizontal slider sends its maximum value when the knob is at the right end of the bar; a vertical slider sends it when the knob is at the top.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the minimum value the receiver can send to its target.

    Declaration

    Swift

    var minValue: Double

    Objective-C

    @property double minValue

    Return Value

    The slider's minimum value. A vertical slider sends its minimum value when its knob is at the bottom; a horizontal slider, when its knob is all the way to the left.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the maximum value the receiver can send to its target.

    Declaration

    Swift

    var maxValue: Double

    Objective-C

    @property double maxValue

    Parameters

    maxValue

    The maximum value of the slider. A horizontal slider sends its maximum value when its knob is all the way to the right; a vertical slider sends its maximum value when its knob is at the top.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – maxValue

  • Sets the minimum value the receiver can send to its target

    Declaration

    Swift

    var minValue: Double

    Objective-C

    @property double minValue

    Parameters

    minValue

    The minimum value of the slider. A horizontal slider sends its minimum value when its knob is all the way to the left; a vertical slider sends its minimum value when its knob is at the bottom.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – minValue

  • 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.

    Declaration

    Swift

    func acceptsFirstMouse(_ mouseDownEvent: NSEvent) -> Bool

    Objective-C

    - (BOOL)acceptsFirstMouse:(NSEvent *)mouseDownEvent

    Parameters

    mouseDownEvent

    The mouse-down event.

    Return Value

    YEStrue if the receiver accepts the first mouse-down event; otherwise, NOfalse. Returns YEStrue by default.

    Discussion

    If you want the receiver to wait for its own mouse-down event, you must override this method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value indicating whether the receiver fixes its values to those values represented by its tick marks.

    Declaration

    Swift

    var allowsTickMarkValuesOnly: Bool

    Objective-C

    @property BOOL allowsTickMarkValuesOnly

    Return Value

    YEStrue if the slider fixes its values to the values represented by its tick marks; otherwise, NOfalse.

    Discussion

    In its implementation of this method, the receiving NSSlider object simply invokes the method of the same name of its NSSliderCell object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func closestTickMarkValueToValue(_ aValue: Double) -> Double

    Objective-C

    - (double)closestTickMarkValueToValue:(double)aValue

    Parameters

    aValue

    The value for which to return the closest tick mark.

    Return Value

    The value of the tick mark closest to aValue.

    Discussion

    In its implementation of this method, the receiver simply invokes the method of the same name of its NSSliderCell instance.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func indexOfTickMarkAtPoint(_ point: NSPoint) -> Int

    Objective-C

    - (NSInteger)indexOfTickMarkAtPoint:(NSPoint)point

    Parameters

    point

    The point representing the location for which to retrieve the tick mark.

    Return Value

    The index of the tick mark closest to the location specified by point. If point is not within the bounding rectangle (plus an extra pixel of space) of any tick mark, the method returns NSNotFound.

    Discussion

    In its implementation of this method, the receiving NSSlider instance simply invokes the method of the same name of its NSSliderCell instance. This method invokes rectOfTickMarkAtIndex: for each tick mark on the slider until it finds a tick mark containing the point.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the number of tick marks associated with the receiver.

    Declaration

    Swift

    var numberOfTickMarks: Int

    Objective-C

    @property NSInteger numberOfTickMarks

    Return Value

    The number of the slider's tick marks.The tick marks assigned to the minimum and maximum values are included. In its implementation of this method, the receiving NNSSlider instance simply invokes the method of the same name of its NSSliderCell instance.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func rectOfTickMarkAtIndex(_ index: Int) -> NSRect

    Objective-C

    - (NSRect)rectOfTickMarkAtIndex:(NSInteger)index

    Parameters

    index

    The index of the tick mark for which to retrieve the bounds. The minimum-value tick mark is at index 0.

    Return Value

    The bounding rectangle of the specified tick mark.

    Discussion

    If no tick mark is associated with index, the method raises NSRangeException. In its implementation of this method, the receiving NSSlider instance simply invokes the method of the same name of its NSSliderCell instance.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets whether the receiver’s values are fixed to the values represented by the tick marks.

    Declaration

    Swift

    var allowsTickMarkValuesOnly: Bool

    Objective-C

    @property BOOL allowsTickMarkValuesOnly

    Parameters

    flag

    YEStrue if the slider's values should be fixed to the values represented by its tick marks; otherwise NOfalse. For example, if a slider has a minimum value of 0, a maximum value of 100, and five markers, the allowable values are 0, 25, 50, 75, and 100. When users move the slider’s knob, it jumps to the tick mark nearest the cursor when the mouse button is released.

    Discussion

    This method has no effect if the slider has no tick marks. In its implementation of this method, the receiving NSSlider instance simply invokes the method of the same name of its NSSliderCell instance.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the number of tick marks displayed by the receiver.

    Declaration

    Swift

    var numberOfTickMarks: Int

    Objective-C

    @property NSInteger numberOfTickMarks

    Parameters

    numberOfTickMarks

    The number of tick marks (including those assigned to the minimum and maximum values) displayed by the slider. By default, this value is 0, and no tick marks appear. The number of tick marks assigned to a slider, along with the slider’s minimum and maximum values, determines the values associated with the tick marks.

    Discussion

    In its implementation of this method, the receiving NSSlider instance simply invokes the method of the same name of its NSSliderCell instance.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets where tick marks appear relative to the receiver.

    Declaration

    Swift

    var tickMarkPosition: NSTickMarkPosition

    Objective-C

    @property NSTickMarkPosition tickMarkPosition

    Parameters

    position

    A constant indicating the position of the tick marks. For horizontal sliders, this can be NSTickMarkBelow (the default) or NSTickMarkAbove; for vertical sliders, this can be NSTickMarkLeft (the default) or NSTickMarkRight.

    Discussion

    This method has no effect if no tick marks have been assigned (that is, numberOfTickMarks returns 0). In its implementation of this method, the receiving NSSlider instance simply invokes the method of the same name of its NSSliderCell instance.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    var tickMarkPosition: NSTickMarkPosition

    Objective-C

    @property NSTickMarkPosition tickMarkPosition

    Return Value

    A constant indicating the position of the tick marks. Possible values are NSTickMarkBelow, NSTickMarkAbove, NSTickMarkLeft, and NSTickMarkRight (the last two are for vertical sliders). The default alignments are NSTickMarkBelow and NSTickMarkLeft.

    Discussion

    In its implementation of this method, the receiving NSSlider instance simply invokes the method of the same name of its NSSliderCell instance.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func tickMarkValueAtIndex(_ index: Int) -> Double

    Objective-C

    - (double)tickMarkValueAtIndex:(NSInteger)index

    Parameters

    index

    The index of the tick mark for which to return the value. The minimum-value tick mark has an index of 0.

    Return Value

    The value of the specified tick mark.

    Discussion

    In its implementation of this method, the receiving NSSlider instance simply invokes the method of the same name of its NSSliderCell instance.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.