O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

NSColorPanel — Mac OS X 10.0

Synopsis

This class implements the system-wide color picker used by all applications. To obtain the shared color panel, use the class method sharedColorPanel. NSColorPanel is a subclass of NSPanel, so to display the color panel on screen, invoke NSWindow’s orderFront: method. NSColorPanel takes a target and an action that are used to notify the application of the user changing the color selection in the color panel. To obtain the color, use the method color.

The color panel optionally displays a slider to change the alpha value of the selected color. This behavior is set with the method setShowsAlpha:. To determine if the color panel is set to use alpha, invoke showsAlpha. It is also possible for an application to add a color list—which is an instance of NSColorList—to the color panel. Color lists are managed using the methods attachColorList: and detachColorList:.

The Application Kit provides the class NSColorWell as an interface to Cocoa’s color-picking system. It is generally sufficient to use NSColorWell as an interface for users to select colors in an application, as it both displays the color associated with it, and provides a means to open the color panel so the user can choose a new color.

image with no caption

@interface NSColorPanel : NSPanel
                                  // Accessor Methods
   - (void)setAction:(SEL)aSelector;
   - (void)setColor:(NSColor *)color;
   - (NSColor *)color

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required