Inherits from: NSControl : NSView : NSResponder : NSObject
Conforms to: NSCoding
(from NSResponder)
NSObject (from NSObject)
Declared in: AppKit/NSSlider.h
An NSSlider displays a range of values for something in the application. An indicator, or knob, notes the current setting. The user can move the knob in the slider's bar to change the setting. If the slider is vertical, its minimum is at its bottom; if it is horizontal, its minimum is at its left.
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, because 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.
Don't use an NSSlider when an NSScroller would be better. A scroller represents the relative position of the visible portion of a view and lets the user choose which portion to view. A slider represents a range of values for something in the application and lets the user choose a setting.
- Asking about the slider's appearance
- - altIncrementValue
- - image
- - knobThickness
- - isVertical
- Changing the slider's appearance
- - setAltIncrementValue:
- - setImage:
- - setKnobThickness:
- Asking about the slider's title
- - title
- - titleCell
- - titleColor
- - titleFont
- Changing the slider's title
- - setTitle:
- - setTitleCell:
- - setTitleColor:
- - setTitleFont:
- Asking about the value limits
- - maxValue
- - minValue
- Changing the value limits
- - setMaxValue:
- - setMinValue:
- Handling mouse-down events
- - acceptsFirstMouse:
- Managing tick marks
- - allowsTickMarkValuesOnly
- - closestTickMarkValueToValue:
- - indexOfTickMarkAtPoint:
- - numberOfTickMarks
- - rectOfTickMarkAtIndex:
- - setAllowsTickMarkValuesOnly:
- - setNumberOfTickMarks:
- - setTickMarkPosition:
- - tickMarkPosition
- - tickMarkValueAtIndex:
- (BOOL)acceptsFirstMouse:(NSEvent
*)mouseDownEvent
YES
by
default, so 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.
- (BOOL)allowsTickMarkValuesOnly
See Also: - setAllowsTickMarkValuesOnly:
- (double)altIncrementValue
Unless you call setAltIncrementValue:, altIncrementValue returns -1.0, and the slider behaves no differently with the Alt key down than with it up.
See Also: - setAltIncrementValue:
- (double)closestTickMarkValueToValue:(double)aValue
See Also: - indexOfTickMarkAtPoint:
- (NSImage *)image
nil
if no
image has been set.See Also: - setImage:
- (int)indexOfTickMarkAtPoint:(NSPoint)point
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. See Also: - closestTickMarkValueToValue:
- (int)isVertical
- (float)knobThickness
See Also: - setKnobThickness:
- (double)maxValue
See Also: - setMaxValue:
- (double)minValue
See Also: - setMinValue:
- (int)numberOfTickMarks
See Also: - setNumberOfTickMarks:
- (NSRect)rectOfTickMarkAtIndex:(int)index
See Also: - indexOfTickMarkAtPoint:
- (void)setAllowsTickMarkValuesOnly:(BOOL)flag
See Also: - allowsTickMarkValuesOnly
- (void)setAltIncrementValue:(double)increment
If you don't call this method, the slider behaves the same with the Alt key down as with it up. This is also the result when you call setAltIncrementValue: with an increment of -1.
See Also: - maxValue, - minValue
- (void)setImage:(NSImage
*)barImage
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.
See Also: - setImage:
- (void)setKnobThickness:(float)thickness
See Also: - knobThickness
- (void)setMaxValue:(double)maxValue
See Also: - maxValue
- (void)setMinValue:(double)minValue
See Also: - minValue
- (void)setNumberOfTickMarks:(int)numberOfTickMarks
See Also: - numberOfTickMarks
- (void)setTickMarkPosition:(NSTickMarkPosition)position
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
- (void)setTitle:(NSString
*)barTitle
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.
See Also: - title
- (void)setTitleCell:(NSCell
*)titleCell
See Also: - titleCell
- (void)setTitleColor:(NSColor
*)color
See Also: - titleColor
- (void)setTitleFont:(NSFont
*)font
See Also: - titleFont
- (NSTickMarkPosition)tickMarkPosition
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:
- (double)tickMarkValueAtIndex:(int)index
- (NSString *)title
See Also: - setTitle:
- (id)titleCell
See Also: - setTitleCell:
- (NSColor *)titleColor
See Also: - setTitleColor:
- (NSFont *)titleFont
See Also: - setTitleFont: