NSColorPanel Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in OS X v10.0 and later. |
| Companion guide | |
| Declared in | NSColorPanel.h |
Overview
The NSColorPanel class provides a standard user interface for selecting color in an application. It provides a number of standard color selection modes and, with the NSColorPickingDefault and NSColorPickingCustom protocols, allows an application to add its own color selection modes. It allows the user to save swatches containing frequently used colors.
Tasks
Obtaining the Shared Color-Panel Object
Configuring the Color Panel
-
– accessoryView -
– isContinuous -
– mode -
– setAccessoryView: -
– setAction: -
– setContinuous: -
– setMode: -
– setShowsAlpha: -
– setTarget: -
– showsAlpha
Managing Color Lists
Setting Color Picker Modes
Setting Color
Getting Color Information
Responding to a Color Change
-
– changeColor:delegate method
Class Methods
dragColor:withEvent:fromView:
Drags a color into a destination view from the specified source view.
Parameters
- color
The color to drag.
- anEvent
The drag event.
- sourceView
The view from which the color was dragged.
Return Value
YES
Discussion
This method is usually invoked by the mouseDown: method of sourceView. The dragging mechanism handles all subsequent events.
Because it is a class method, dragColor:withEvent:fromView: can be invoked whether or not the instance of NSColorPanel exists.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColorPanel.hsetPickerMask:
Determines which color selection modes are available in an application’s NSColorPanel.
Parameters
- mask
One or more logically ORed color mode masks described in “Color Picker Mode Masks.”
Discussion
This method has an effect only before an NSColorPanel object is instantiated.
If you create a class that implements the color-picking protocols (NSColorPickingDefault and NSColorPickingCustom), you may want to give it a unique mask—one different from those defined for the standard color pickers. To display your color picker, your application will need to logically OR that unique mask with the standard color mask constants when invoking this method.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hsetPickerMode:
Specifies the color panel’s initial picker.
Parameters
- mode
A constant specifying which color picker mode is initially visible. This is one of the symbolic constants described in “Color Panel Modes.”
Discussion
This method may be called at any time, whether or not an application’s NSColorPanel has been instantiated.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hsharedColorPanel
Returns the shared NSColorPanel instance, creating it if necessary.
Return Value
The shared NSColorPanel instance.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColorPanel.hsharedColorPanelExists
Returns a Boolean value indicating whether the NSColorPanel has been created already.
Return Value
YES if the NSColorPanel has been created already; otherwise NO.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hInstance Methods
accessoryView
Returns the accessory view.
Return Value
The accessory view or nil if there is none.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.halpha
Returns the receiver’s current alpha value based on its opacity slider.
Return Value
The alpha value of the NSColorPanel. This is 1.0 (opaque) if the panel has no opacity slider.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hattachColorList:
Adds the list of NSColor objects specified to all the color pickers in the receiver that display color lists by invoking attachColorList: on all color pickers in the application.
Parameters
- colorList
The list of colors to add to the color pickers in the receiver.
Discussion
An application should use this method to add an NSColorList saved with a document in its file package or in a directory other than NSColorList’s standard search directories.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hcolor
Returns the currently selected color in the receiver.
Return Value
The currently selected color.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hdetachColorList:
Removes the list of colors from all the color pickers in the receiver that display color lists by invoking detachColorList: on all color pickers in the application.
Parameters
- colorList
The list of
NSColorobjects to remove from the color pickers in the color panel.
Discussion
Your application should use this method to remove an NSColorList saved with a document in its file package or in a directory other than NSColorList's standard search directories.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hisContinuous
Returns a Boolean value indicating whether the receiver continuously sends the action message to the target.
Return Value
YES if the receiver continuously sends the action message to the target as the user manipulates the color picker; otherwise NO.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hmode
Returns the color picker mode of the receiver.
Return Value
A constant indicating the current color picker mode. See “Color Panel Modes.”
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hsetAccessoryView:
Sets the accessory view displayed in the receiver.
Parameters
- aView
The accessory view displayed in the receiver. The accessory view can be any custom view you want to display with
NSColorPanel, such as a view offering color blends in a drawing program. The accessory view is displayed below the color picker and above the color swatches in theNSColorPanel. TheNSColorPanelautomatically resizes to accommodate the accessory view.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hsetAction:
Sets the color panel's action message.
Return Value
The action message. When you select a color in the color panel NSColorPanel sends its action to its target, provided that neither the action nor the target is nil. The action is NULL by default.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hsetColor:
Sets the color of the receiver.
Parameters
- color
The color of the
NSColorPanel.
Discussion
This method posts an NSColorPanelColorDidChangeNotification with the receiver to the default notification center.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hsetContinuous:
Sets the receiver to send the action message to its target continuously as the user sets the color.
Parameters
- flag
YESto have the receiver send its action message to its target continuously as the color of theNSColorPanelis set by the user; otherwiseNO. Set this toYESif, for example, you want to continuously update the color of the target.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hsetMode:
Sets the mode of the receiver the mode is one of the modes allowed by the color mask.
Parameters
- mode
A constant specifying the mode of the color panel. These constants are described in “Color Panel Modes.” The color mask is set when you first create the shared instance of
NSColorPanelfor an application.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hsetShowsAlpha:
Tells the receiver whether or not to show alpha values and an opacity slider.
Parameters
- flag
YESto have the color panel show alpha values and an opacity slider; otherwiseNO.
Discussion
Note that calling the NSColor method setIgnoresAlpha: with a value of YES overrides any value set with this method.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hsetTarget:
Sets the target of the receiver.
Parameters
- target
The target of the receiver. When you select a color in the color panel
NSColorPanelsends its action to its target, provided that neither the action nor the target isnil. The target isnilby default.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hshowsAlpha
Returns a Boolean value indicating whether or not the receiver shows alpha values and an opacity slider.
Return Value
YES if the color picker shows alpha values and an opacity slider; otherwise NO.
Discussion
Note that calling the NSColor method setIgnoresAlpha: with a value of YES overrides any value set with setShowsAlpha:.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColorPanel.hDelegate Methods
changeColor:
Sent to the first responder when the user selects a color in an NSColorPanel object.
Parameters
- sender
The
NSColorPanelsending the message.
Discussion
When the user selects a color in an NSColorPanel object, the panel sends a changeColor: action message to the first responder. You can override this method in any responder that needs to respond to a color change.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColorPanel.hConstants
Color Picker Mode Masks
Used to specify in the setPickerMask: class method which of the color modes the NSColorPanel can use.
enum {
NSColorPanelGrayModeMask = 0x00000001,
NSColorPanelRGBModeMask = 0x00000002,
NSColorPanelCMYKModeMask = 0x00000004,
NSColorPanelHSBModeMask = 0x00000008,
NSColorPanelCustomPaletteModeMask = 0x00000010,
NSColorPanelColorListModeMask = 0x00000020,
NSColorPanelWheelModeMask = 0x00000040,
NSColorPanelCrayonModeMask = 0x00000080,
NSColorPanelAllModesMask = 0x0000ffff
};
Constants
NSColorPanelGrayModeMaskGrayscale-alpha.
Available in OS X v10.0 and later.
Declared in
NSColorPanel.h.NSColorPanelRGBModeMaskRed-green-blue.
Available in OS X v10.0 and later.
Declared in
NSColorPanel.h.NSColorPanelCMYKModeMaskCyan-yellow-magenta-black.
Available in OS X v10.0 and later.
Declared in
NSColorPanel.h.NSColorPanelHSBModeMaskHue-saturation-brightness.
Available in OS X v10.0 and later.
Declared in
NSColorPanel.h.NSColorPanelCustomPaletteModeMaskCustom palette.
Available in OS X v10.0 and later.
Declared in
NSColorPanel.h.NSColorPanelColorListModeMaskCustom color list.
Available in OS X v10.0 and later.
Declared in
NSColorPanel.h.NSColorPanelWheelModeMaskColor wheel.
Available in OS X v10.0 and later.
Declared in
NSColorPanel.h.NSColorPanelCrayonModeMaskCrayons.
Declared in
NSColorPanel.h.Available in OS X v10.2 and later.
NSColorPanelAllModesMaskAll of the above.
Available in OS X v10.0 and later.
Declared in
NSColorPanel.h.
Discussion
For more information, see “Choosing the Color Pickers in a Color Panel”.
Declared In
NSColorPanel.hNSColorPanelMode
A type defined for the enum constants specifying color panel modes.
typedef NSInteger NSColorPanelMode;
Availability
- Available in OS X v10.5 and later.
Declared In
NSColorPanel.hColor Panel Modes
Specify the active color mode used when an application’s instance of NSColorPanel is masked for more than one color mode.
enum {
NSNoModeColorPanel = -1,
NSGrayModeColorPanel = 0,
NSRGBModeColorPanel = 1,
NSCMYKModeColorPanel = 2,
NSHSBModeColorPanel = 3,
NSCustomPaletteModeColorPanel = 4,
NSColorListModeColorPanel = 5,
NSWheelModeColorPanel = 6,
NSCrayonModeColorPanel = 7
};
Constants
NSNoModeColorPanelIndicates no color panel mode.
Available in OS X version 10.5 and later.
Declared in
NSColorPanel.h.NSGrayModeColorPanelGrayscale-alpha
Available in OS X v10.0 and later.
Declared in
NSColorPanel.h.NSRGBModeColorPanelRed-green-blue
Available in OS X v10.0 and later.
Declared in
NSColorPanel.h.NSCMYKModeColorPanelCyan-yellow-magenta-black
Available in OS X v10.0 and later.
Declared in
NSColorPanel.h.NSHSBModeColorPanelHue-saturation-brightness
Available in OS X v10.0 and later.
Declared in
NSColorPanel.h.NSCustomPaletteModeColorPanelCustom palette
Available in OS X v10.0 and later.
Declared in
NSColorPanel.h.NSColorListModeColorPanelCustom color list
Available in OS X v10.0 and later.
Declared in
NSColorPanel.h.NSWheelModeColorPanelColor wheel
Available in OS X v10.0 and later.
Declared in
NSColorPanel.h.NSCrayonModeColorPanelCrayons.
Declared in
NSColorPanel.h.Available in OS X v10.2 and later.
Discussion
These enum constants are specified or returned in the instance methods mode and setMode:, and in the setPickerMode:class method. For more information, see “Choosing the Color Pickers in a Color Panel”.
Declared In
NSColorPanel.hNotifications
NSColorPanelColorDidChangeNotification
NSColorPanel is set, as when setColor: is invoked.The notification object is the notifying NSColorPanel. This notification does not contain a userInfo dictionary.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColorPanel.h© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-28)