Inherits From:
NSControl : NSView : NSResponder : NSObject
Conforms To:
NSCoding (from NSResponder)
NSObject (from NSObject)
Declared In:
AppKit/NSSlider.h
The minimum and maximum can be obtained with the minValue
and maxValue
methods, and set with the setMinValue:
and setMaxValue:
methods. To read the value represented by the current position of the knob, you use an NSControl method like floatValue
; conversely, to send a value to the slider, you use a NSControl method like setFloatValue:
.
By default, an NSSlider is a continuous NSControl: while the user drags the slider's knob, the slider sends its action message continuously. If, instead, you want the slider to reserve its action message until the mouse is released, invoke setContinuous:
(an NSControl method) with an argument of NO.
In its bar, an NSSlider can display an image, a title, or both. The title can be drawn in any color and any font. However, since a title in the bar may be obscured by the slider knob, you will more often label a slider by placing an NSTextField near it.
An NSSlider can have tick marks to either side of it. The values represented by the tick marks are determined by the number of tick marks and the minimum and maximum values of the slider; a slider's values can be pegged to the values represented by the tick marks.
Like most NSControls, NSSlider relies heavily on a related cell class, NSSliderCell. For more information, see the NSSliderCell class specification.
acceptsFirstMouse:
(NSEvent *)mouseDownEvent
Returns YES by default, so that a single mouse-down event can simultaneously activate the window and take hold of the slider's knob.
If you want the slider to wait for its own mouse-down event, you must override this method.
allowsTickMarkValuesOnly
Returns whether the receiver fixes its values to those values represented by its tick marks. In its implementation of this method, the receiving NSSlider simply invokes the method of the same name of its NSSliderCell.
See also:
- setAllowsTickMarkValuesOnly:
image
Returns the image that the slider displays in its bar, or nil
if no image has been set.
indexOfTickMarkAtPoint:
(NSPoint)point
Returns the index of the tick mark closest to the location of the slider represented by point. If point is not within the bounding rectangle (plus an extra pixel of space) of any tick mark, the method returns NSNotFound. In its implementation of this method, the receiving NSSlider simply invokes the method of the same name of its NSSliderCell. This method invokes rectOfTickMarkAtIndex:
for each tick mark on the slider until it finds a tick mark containing the point.
isVertical
Returns 1 if the slider 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.
knobThickness
Returns the knob's thickness, in pixels. 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.
maxValue
Returns the maximum value that the slider can send to its target. 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.
minValue
Returns the minimum value that the slider can send to its target. 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.
numberOfTickMarks
Returns the number of tick marks associated with the slider. The tick marks assigned to the minimum and maximum values are included. In its implementation of this method, the receiving NSSlider simply invokes the method of the same name of its NSSliderCell.
See also:
- setNumberOfTickMarks:
rectOfTickMarkAtIndex:
(int)index
Returns the bounding rectangle of the tick mark identified by index (the minimum-value tick mark is at index 0). If no tick mark is associated with index, the method raises NSRangeException. In its implementation of this method, the receiving NSSlider simply invokes the method of the same name of its NSSliderCell.
See also:
- indexOfTickMarkAtPoint:
setAllowsTickMarkValuesOnly:
(BOOL)flag
Sets whether the receiver's values are fixed to the values represented by the tick marks. 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 is released. This method has no effect if the slider has no tick marks. In its implementation of this method, the receiving NSSlider simply invokes the method of the same name of its NSSliderCell.
See also:
- allowsTickMarkValuesOnly
setImage:
(NSImage *)barImage
Sets the image that the slider displays in the bar behind its knob. 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.
setKnobThickness:
(float)thickness
Lets you set the knob's thickness, measured in pixels. 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.
See also:
- knobThickness
setMaxValue:
(double)maxValue
Sets the maximum value that the slider can send to its target-the value that a horizontal slider sends when its knob is all the way to the right, or that a vertical slider sends when its knob is at the top.
setMinValue:
(double)minValue
Sets the minimum value that the slider can send to its target. 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.
setNumberOfTickMarks:
(int)numberOfTickMarks
Sets the number of tick marks displayed by the receiver (which include those assigned to the minimum and maximumvalues). By default, this value is zero, and no tick marks appear. The number of tick marks assigned to a slider, along with the slider's minimum and maximum values, determine the values associated with the tick marks. In its implementation of this method, the receiving NSSlider simply invokes the method of the same name of its NSSliderCell.
See also:
- numberOfTickMarks
setTickMarkPosition:
(NSTickMarkPosition)position
Sets where tick marks appear relative to the receiver. For horizontal sliders, position can be NSTickMarksBelow (the default) or NSTickMarksAbove; for vertical sliders, position can be NSTickMarksLeft (the default) or NSTickMarksRight. This method has no effect if no tick marks have been assigned (that is, numberOfTickMarks
returns zero). In its implementation of this method, the receiving NSSlider simply invokes the method of the same name of its NSSliderCell.
See also:
- tickMarkPosition
setTitle:
(NSString *)barTitle
Sets the title that the slider displays in the bar behind its knob.
The knob may cover part or all of the title. If you want the title to be visible all of the time, you're better off placing a label near the slider.
setTitleCell:
(NSCell *)titleCell
Sets the cell used to draw the slider's title. You only need to invoke this method if the default title cell, NSTextFieldCell, doesn't suit your needs-that is, if 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 TextFieldCell.
See also:
- titleCell
setTitleColor:
(NSColor *)color
Sets the color used to draw the slider's title.
setTitleFont:
(NSFont *)font
Sets the font used to draw the slider's title.
tickMarkPosition
Returns how the receiver's tick marks are aligned with it: NSTickMarkBelow, NSTickMarkAbove, NSTickMarkLeft, or NSTickMarkRight (the last two are for vertical sliders). The default alignments are NSTickMarkBelow and NSTickMarkLeft. In its implementation of this method, the receiving NSSlider simply invokes the method of the same name of its NSSliderCell.
See also:
- setTickMarkPosition:
tickMarkValueAtIndex:
(int)index
Returns the receiver's value represented by the tick mark at index (the minimum-value tick mark has an index of zero). In its implementation of this method, the receiving NSSlider simply invokes the method of the same name of its NSSliderCell.
title
Returns the slider's title. The default title is the empty string ("").
titleCell
Returns the cell used to draw the title. The default is an NSTextFieldCell.
titleColor
Returns the color used to draw the slider's title. The default color is NSColor's controlTextColor
.
titleFont
Returns the font used to draw the slider's title.
See also:
- setTitleColor: