Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/AppKit.framework |
Availability | Available in Mac OS X v10.0 and later. |
Companion guide | |
Declared in | NSSlider.h |
Related sample code |
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.
The NSSlider
class uses the NSSliderCell
class to implement its user interface.
– allowsTickMarkValuesOnly
– closestTickMarkValueToValue:
– indexOfTickMarkAtPoint:
– numberOfTickMarks
– rectOfTickMarkAtIndex:
– setAllowsTickMarkValuesOnly:
– setNumberOfTickMarks:
– setTickMarkPosition:
– tickMarkPosition
– tickMarkValueAtIndex:
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.
- (BOOL)acceptsFirstMouse:(NSEvent *)mouseDownEvent
The mouse-down event.
YES
if the receiver accepts the first mouse-down event; otherwise, NO
. Returns YES
by default.
If you want the receiver to wait for its own mouse-down event, you must override this method.
NSSlider.h
Returns a Boolean value indicating whether the receiver fixes its values to those values represented by its tick marks.
- (BOOL)allowsTickMarkValuesOnly
YES
if the slider fixes its values to the values represented by its tick marks; otherwise, NO
.
In its implementation of this method, the receiving NSSlider
object simply invokes the method of the same name of its NSSliderCell
object.
NSSlider.h
Returns the amount by which the receiver changes its value when the user Option–drags the slider knob.
- (double)altIncrementValue
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.
NSSlider.h
Returns the value of the tick mark closest to the specified value.
- (double)closestTickMarkValueToValue:(double)aValue
The value for which to return the closest tick mark.
The value of the tick mark closest to aValue
.
In its implementation of this method, the receiver simply invokes the method of the same name of its NSSliderCell
instance.
NSSlider.h
This method has been deprecated. Returns nil
.
- (NSImage *)image
NSSlider.h
Returns the index of the tick mark closest to the location of the receiver represented by the given point.
- (NSInteger)indexOfTickMarkAtPoint:(NSPoint)point
The point representing the location for which to retrieve the tick mark.
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
.
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.
NSSlider.h
Returns an integer indicating the orientation (horizontal or vertical) of the slider.
- (NSInteger)isVertical
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.
NSSlider.h
Returns the knob’s thickness, in pixels.
- (CGFloat)knobThickness
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.
NSSlider.h
Returns the maximum value the receiver can send to its target.
- (double)maxValue
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.
NSSlider.h
Returns the minimum value the receiver can send to its target.
- (double)minValue
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.
NSSlider.h
Returns the number of tick marks associated with the receiver.
- (NSInteger)numberOfTickMarks
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.
NSSlider.h
Returns the bounding rectangle of the tick mark at the given index.
- (NSRect)rectOfTickMarkAtIndex:(NSInteger)index
The index of the tick mark for which to retrieve the bounds. The minimum-value tick mark is at index 0.
The bounding rectangle of the specified tick mark.
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.
NSSlider.h
Sets whether the receiver’s values are fixed to the values represented by the tick marks.
- (void)setAllowsTickMarkValuesOnly:(BOOL)flag
YES
if the slider's values should be fixed to the values represented by its tick marks; otherwise NO
. 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.
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.
NSSlider.h
Sets the amount by which the NSSliderCell
modifies its value when the user Option-drags the knob.
- (void)setAltIncrementValue:(double)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.
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.
NSSlider.h
This method has been deprecated. Sets the image the receiver displays in the bar behind its knob.
- (void)setImage:(NSImage *)barImage
The image to set.
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.
NSSlider.h
This method has been deprecated. Lets you set the knob’s thickness, measured in pixels.
- (void)setKnobThickness:(CGFloat)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.
NSSlider.h
Sets the maximum value the receiver can send to its target.
- (void)setMaxValue:(double)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.
NSSlider.h
Sets the minimum value the receiver can send to its target
- (void)setMinValue:(double)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.
NSSlider.h
Sets the number of tick marks displayed by the receiver.
- (void)setNumberOfTickMarks:(NSInteger)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.
In its implementation of this method, the receiving NSSlider
instance simply invokes the method of the same name of its NSSliderCell
instance.
NSSlider.h
Sets where tick marks appear relative to the receiver.
- (void)setTickMarkPosition:(NSTickMarkPosition)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
.
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.
NSSlider.h
This method has been deprecated. Sets the title the receiver displays in the bar behind its knob.
- (void)setTitle:(NSString *)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.
NSSlider.h
This method has been deprecated. Sets the cell used to draw the receiver’s title.
- (void)setTitleCell:(NSCell *)titleCell
The cell used to draw the title.
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
.
NSSlider.h
This method has been deprecated. Sets the color used to draw the receiver’s title.
- (void)setTitleColor:(NSColor *)color
The title color.
NSSlider.h
This method has been deprecated. Sets the font used to draw the receiver’s title.
- (void)setTitleFont:(NSFont *)font
The title font.
NSSlider.h
Returns how the receiver’s tick marks are aligned with it.
- (NSTickMarkPosition)tickMarkPosition
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
.
In its implementation of this method, the receiving NSSlider
instance simply invokes the method of the same name of its NSSliderCell
instance.
NSSlider.h
Returns the receiver’s value represented by the tick mark at the specified index.
- (double)tickMarkValueAtIndex:(NSInteger)index
The index of the tick mark for which to return the value. The minimum-value tick mark has an index of 0.
The value of the specified tick mark.
In its implementation of this method, the receiving NSSlider
instance simply invokes the method of the same name of its NSSliderCell
instance.
NSSlider.h
Returns the receiver’s title.
- (NSString *)title
The title. The default title is the empty string (@""
).
NSSlider.h
This method has been deprecated. Returns nil
.
- (id)titleCell
NSSlider.h
This method has been deprecated. Returns nil
.
- (NSColor *)titleColor
NSSlider.h
This method has been deprecated. Returns nil
.
- (NSFont *)titleFont
NSSlider.h
© 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-05-23)