< Previous PageNext Page > Hide TOC

About Sliders

A slider is a control that displays a range of values and has an indicator, or knob, which indicates the current setting. Optionally, it can have tick marks at regularly spaced intervals. A slider can be a bar or a dial. The user moves the knob along the slider’s bar, or around the dial, to change the setting.

Note: Don’t use an NSSlider object 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.

A slider’s behavior and appearance is controlled by the class NSSliderCell. An NSSliderCell object must be contained within a subclass of NSControl. If you need one slider, use an NSSlider object that contains a single NSSliderCell object. If you need a group of related sliders, use an NSMatrix object that contains several NSSliderCell objects. Most NSSliderCell methods have covers in NSSlider, which simply call the NSSliderCell equivalent. For more information, see the NSSliderCell and NSSlider class specifications.

Note: For a description of the relationship between controls (NSControl objects) and cells (NSCell objects), see the section on control-cell architecture in “The Core Application Architecture“ of Cocoa Fundamentals Guide.

Contents:

Setting a Slider’s Values
Displaying a Slider’s Name and Values


Setting a Slider’s Values

To set the slider’s minimum and maximum values, use setMinValue: and setMaxValue:. To read the slider’s value, as represented by the knob’s current position, use an NSControl “get” method, such as floatValue;. To set the slider’s value, use an NSControl “set” method, such as setFloatValue:.

Displaying a Slider’s Name and Values

You should use text fields to display the slider’s name, minimum value, maximum value, and tick-mark value. Although you can set a title for a slider that’s displayed automatically, it’s displayed right in the slider’s bar and is easily obscured by the knob. There is no way for a slider to display automatically its minimum, maximum, and tick-mark values.



< Previous PageNext Page > Hide TOC


© 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-10-03)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.