Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/AppKit.framework |
Availability | Available in Mac OS X v10.0 and later. |
Companion guide | |
Declared in | NSColorPanel.h |
Related sample code |
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.
– accessoryView
– isContinuous
– mode
– setAccessoryView:
– setAction:
– setContinuous:
– setMode:
– setShowsAlpha:
– setTarget:
– showsAlpha
– changeColor:
delegate method
Drags a color into a destination view from the specified source view.
+ (BOOL)dragColor:(NSColor *)color withEvent:(NSEvent *)anEvent fromView:(NSView *)sourceView
The color to drag.
The drag event.
The view from which the color was dragged.
YES
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.
NSColorPanel.h
Determines which color selection modes are available in an application’s NSColorPanel
.
+ (void)setPickerMask:(NSUInteger)mask
One or more logically ORed color mode masks described in Color Panel Mode Masks.
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.
NSColorPanel.h
Specifies the color panel’s initial picker.
+ (void)setPickerMode:(NSColorPanelMode)mode
A constant specifying which color picker mode is initially visible. This is one of the symbolic constants described in Color Panel Modes.
This method may be called at any time, whether or not an application’s NSColorPanel
has been instantiated.
NSColorPanel.h
Returns the shared NSColorPanel
instance, creating it if necessary.
+ (NSColorPanel *)sharedColorPanel
The shared NSColorPanel
instance.
NSColorPanel.h
Returns a Boolean value indicating whether the NSColorPanel
has been created already.
+ (BOOL)sharedColorPanelExists
YES
if the NSColorPanel
has been created already; otherwise NO
.
NSColorPanel.h
Returns the accessory view.
- (NSView *)accessoryView
The accessory view or nil
if there is none.
NSColorPanel.h
Returns the receiver’s current alpha value based on its opacity slider.
- (CGFloat)alpha
The alpha value of the NSColorPanel
. This is 1.0 (opaque) if the panel has no opacity slider.
NSColorPanel.h
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.
- (void)attachColorList:(NSColorList *)colorList
The list of colors to add to the color pickers in the receiver.
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.
NSColorPanel.h
Returns the currently selected color in the receiver.
- (NSColor *)color
The currently selected color.
NSColorPanel.h
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.
- (void)detachColorList:(NSColorList *)colorList
The list of NSColor
objects to remove from the color pickers in the color panel.
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.
NSColorPanel.h
Returns a Boolean value indicating whether the receiver continuously sends the action message to the target.
- (BOOL)isContinuous
YES
if the receiver continuously sends the action message to the target as the user manipulates the color picker; otherwise NO
.
NSColorPanel.h
Returns the color picker mode of the receiver.
- (NSColorPanelMode)mode
A constant indicating the current color picker mode. See Color Panel Modes.
NSColorPanel.h
Sets the accessory view displayed in the receiver.
- (void)setAccessoryView:(NSView *)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 the NSColorPanel
. The NSColorPanel
automatically resizes to accommodate the accessory view.
NSColorPanel.h
Sets the color panel's action message.
- (void)setAction:(SEL)action
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.
See Action Messages for additional information on action messages.
NSColorPanel.h
Sets the color of the receiver.
- (void)setColor:(NSColor *)color
The color of the NSColorPanel
.
This method posts an NSColorPanelColorDidChangeNotification
with the receiver to the default notification center.
NSColorPanel.h
Sets the receiver to send the action message to its target continuously as the user sets the color.
- (void)setContinuous:(BOOL)flag
YES
to have the receiver send its action message to its target continuously as the color of the NSColorPanel
is set by the user; otherwise NO
. Set this to YES
if, for example, you want to continuously update the color of the target.
NSColorPanel.h
Sets the mode of the receiver the mode is one of the modes allowed by the color mask.
- (void)setMode:(NSColorPanelMode)mode
A constant specifying the mode of the color panel. These constants are described in Color Picker Modes. The color mask is set when you first create the shared instance of NSColorPanel
for an application.
NSColorPanel.h
Tells the receiver whether or not to show alpha values and an opacity slider.
- (void)setShowsAlpha:(BOOL)flag
YES
to have the color panel show alpha values and an opacity slider; otherwise NO
.
Note that calling the NSColor
method setIgnoresAlpha:
with a value of YES
overrides any value set with this method.
NSColorPanel.h
Sets the target of the receiver.
- (void)setTarget:(id)target
The target of the receiver. 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 target is nil
by default.
NSColorPanel.h
Returns a Boolean value indicating whether or not the receiver shows alpha values and an opacity slider.
- (BOOL)showsAlpha
YES
if the color picker shows alpha values and an opacity slider; otherwise NO
.
Note that calling the NSColor
method setIgnoresAlpha:
with a value of YES
overrides any value set with setShowsAlpha:
.
NSColorPanel.h
Sent to the first responder when the user selects a color in an NSColorPanel
object.
- (void)changeColor:(id)sender
The NSColorPanel
sending the message.
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.
NSColorPanel.h
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 };
NSColorPanelGrayModeMask
Grayscale-alpha.
Available in Mac OS X v10.0 and later.
Declared in NSColorPanel.h
.
NSColorPanelRGBModeMask
Red-green-blue.
Available in Mac OS X v10.0 and later.
Declared in NSColorPanel.h
.
NSColorPanelCMYKModeMask
Cyan-yellow-magenta-black.
Available in Mac OS X v10.0 and later.
Declared in NSColorPanel.h
.
NSColorPanelHSBModeMask
Hue-saturation-brightness.
Available in Mac OS X v10.0 and later.
Declared in NSColorPanel.h
.
NSColorPanelCustomPaletteModeMask
Custom palette.
Available in Mac OS X v10.0 and later.
Declared in NSColorPanel.h
.
NSColorPanelColorListModeMask
Custom color list.
Available in Mac OS X v10.0 and later.
Declared in NSColorPanel.h
.
NSColorPanelWheelModeMask
Color wheel.
Available in Mac OS X v10.0 and later.
Declared in NSColorPanel.h
.
NSColorPanelCrayonModeMask
Crayons.
Declared in NSColorPanel.h
.
Available in Mac OS X v10.2 and later.
NSColorPanelAllModesMask
All of the above.
Available in Mac OS X v10.0 and later.
Declared in NSColorPanel.h
.
For more information, see “Choosing the Color Pickers in a Color Panel”.
NSColorPanel.h
A type defined for the enum
constants specifying color panel modes.
typedef NSInteger NSColorPanelMode;
NSColorPanel.h
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 };
NSNoModeColorPanel
Indicates no color panel mode.
Available in Mac OS X version 10.5 and later.
Declared in NSColorPanel.h
.
NSGrayModeColorPanel
Grayscale-alpha
Available in Mac OS X v10.0 and later.
Declared in NSColorPanel.h
.
NSRGBModeColorPanel
Red-green-blue
Available in Mac OS X v10.0 and later.
Declared in NSColorPanel.h
.
NSCMYKModeColorPanel
Cyan-yellow-magenta-black
Available in Mac OS X v10.0 and later.
Declared in NSColorPanel.h
.
NSHSBModeColorPanel
Hue-saturation-brightness
Available in Mac OS X v10.0 and later.
Declared in NSColorPanel.h
.
NSCustomPaletteModeColorPanel
Custom palette
Available in Mac OS X v10.0 and later.
Declared in NSColorPanel.h
.
NSColorListModeColorPanel
Custom color list
Available in Mac OS X v10.0 and later.
Declared in NSColorPanel.h
.
NSWheelModeColorPanel
Color wheel
Available in Mac OS X v10.0 and later.
Declared in NSColorPanel.h
.
NSCrayonModeColorPanel
Crayons.
Declared in NSColorPanel.h
.
Available in Mac OS X v10.2 and later.
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”.
NSColorPanel.h
Posted when the color of the NSColorPanel
is set, as when setColor:
is invoked.
The notification object is the notifying NSColorPanel
. This notification does not contain a userInfo dictionary.
NSColorPanel.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-28)