Mac Developer Library

Developer

AppKit Framework Reference NSColorPanel Class Reference

Options
Deployment Target:

On This Page
Language:

NSColorPanel

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.

Inheritance


Import Statement


import AppKit @import AppKit;

Availability


Available in OS X v10.0 and later.
  • Returns the shared NSColorPanel instance, creating it if necessary.

    Declaration

    Swift

    class func sharedColorPanel() -> NSColorPanel

    Objective-C

    + (NSColorPanel *)sharedColorPanel

    Return Value

    The shared NSColorPanel instance.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value indicating whether the NSColorPanel has been created already.

    Declaration

    Swift

    class func sharedColorPanelExists() -> Bool

    Objective-C

    + (BOOL)sharedColorPanelExists

    Return Value

    YEStrue if the NSColorPanel has been created already; otherwise NOfalse.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the accessory view.

    Declaration

    Swift

    var accessoryView: NSView?

    Objective-C

    @property(strong) NSView *accessoryView

    Return Value

    The accessory view or nil if there is none.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • isContinuous isContinuous Available in OS X v10.0 through OS X v10.9

    Returns a Boolean value indicating whether the receiver continuously sends the action message to the target.

    Declaration

    Objective-C

    - (BOOL)isContinuous

    Return Value

    YEStrue if the receiver continuously sends the action message to the target as the user manipulates the color picker; otherwise NOfalse.

    Import Statement

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Returns the color picker mode of the receiver.

    Declaration

    Swift

    var mode: NSColorPanelMode

    Objective-C

    @property NSColorPanelMode mode

    Return Value

    A constant indicating the current color picker mode. See Color Panel Modes.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the accessory view displayed in the receiver.

    Declaration

    Swift

    var accessoryView: NSView?

    Objective-C

    @property(strong) NSView *accessoryView

    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 the NSColorPanel. The NSColorPanel automatically resizes to accommodate the accessory view.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the color panel's action message.

    Declaration

    Swift

    func setAction(_ aSelector: Selector)

    Objective-C

    - (void)setAction:(SEL)aSelector

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setTarget:

  • Sets the receiver to send the action message to its target continuously as the user sets the color.

    Declaration

    Swift

    var continuous: Bool

    Objective-C

    @property(getter=isContinuous) BOOL continuous

    Parameters

    flag

    YEStrue to have the receiver send its action message to its target continuously as the color of the NSColorPanel is set by the user; otherwise NOfalse. Set this to YEStrue if, for example, you want to continuously update the color of the target.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the mode of the receiver the mode is one of the modes allowed by the color mask.

    Declaration

    Swift

    var mode: NSColorPanelMode

    Objective-C

    @property NSColorPanelMode mode

    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 NSColorPanel for an application.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Tells the receiver whether or not to show alpha values and an opacity slider.

    Declaration

    Swift

    var showsAlpha: Bool

    Objective-C

    @property BOOL showsAlpha

    Parameters

    flag

    YEStrue to have the color panel show alpha values and an opacity slider; otherwise NOfalse.

    Discussion

    Note that calling the NSColor method setIgnoresAlpha: with a value of YEStrue overrides any value set with this method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the target of the receiver.

    Declaration

    Swift

    func setTarget(_ target: AnyObject?)

    Objective-C

    - (void)setTarget:(id)target

    Parameters

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value indicating whether or not the receiver shows alpha values and an opacity slider.

    Declaration

    Swift

    var showsAlpha: Bool

    Objective-C

    @property BOOL showsAlpha

    Return Value

    YEStrue if the color picker shows alpha values and an opacity slider; otherwise NOfalse.

    Discussion

    Note that calling the NSColor method setIgnoresAlpha: with a value of YEStrue overrides any value set with setShowsAlpha:.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • 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.

    Declaration

    Swift

    func attachColorList(_ colorList: NSColorList)

    Objective-C

    - (void)attachColorList:(NSColorList *)colorList

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • 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.

    Declaration

    Swift

    func detachColorList(_ colorList: NSColorList)

    Objective-C

    - (void)detachColorList:(NSColorList *)colorList

    Parameters

    colorList

    The list of NSColor objects 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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Determines which color selection modes are available in an application’s NSColorPanel.

    Declaration

    Swift

    class func setPickerMask(_ mask: NSColorPanelOptions)

    Objective-C

    + (void)setPickerMask:(NSColorPanelOptions)mask

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Specifies the color panel’s initial picker.

    Declaration

    Swift

    class func setPickerMode(_ mode: NSColorPanelMode)

    Objective-C

    + (void)setPickerMode:(NSColorPanelMode)mode

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Drags a color into a destination view from the specified source view.

    Declaration

    Swift

    class func dragColor(_ color: NSColor, withEvent anEvent: NSEvent, fromView sourceView: NSView) -> Bool

    Objective-C

    + (BOOL)dragColor:(NSColor *)color withEvent:(NSEvent *)anEvent fromView:(NSView *)sourceView

    Parameters

    color

    The color to drag.

    anEvent

    The drag event.

    sourceView

    The view from which the color was dragged.

    Return Value

    YEStrue

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the color of the receiver.

    Declaration

    Swift

    @NSCopying var color: NSColor

    Objective-C

    @property(copy) NSColor *color

    Parameters

    color

    The color of the NSColorPanel.

    Discussion

    This method posts an NSColorPanelColorDidChangeNotification with the receiver to the default notification center.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – color

  • Returns the receiver’s current alpha value based on its opacity slider.

    Declaration

    Swift

    var alpha: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat alpha

    Return Value

    The alpha value of the NSColorPanel. This is 1.0 (opaque) if the panel has no opacity slider.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the currently selected color in the receiver.

    Declaration

    Swift

    @NSCopying var color: NSColor

    Objective-C

    @property(copy) NSColor *color

    Return Value

    The currently selected color.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setColor:

  • Sent to the first responder when the user selects a color in an NSColorPanel object.

    Objective-C

    - (void)changeColor:(id)sender

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

Data Types

  • A type defined for the enum constants specifying color panel modes.

    Declaration

    Swift

    enum NSColorPanelMode : Int { case NSNoModeColorPanel case NSGrayModeColorPanel case NSRGBModeColorPanel case NSCMYKModeColorPanel case NSHSBModeColorPanel case NSCustomPaletteModeColorPanel case NSColorListModeColorPanel case NSWheelModeColorPanel case NSCrayonModeColorPanel }

    Objective-C

    typedef NSInteger NSColorPanelMode;

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Used to specify in the setPickerMask: class method which of the color modes the NSColorPanel can use.

    Declaration

    Swift

    struct NSColorPanelOptions : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var GrayModeMask: NSColorPanelOptions { get } static var RGBModeMask: NSColorPanelOptions { get } static var CMYKModeMask: NSColorPanelOptions { get } static var HSBModeMask: NSColorPanelOptions { get } static var CustomPaletteModeMask: NSColorPanelOptions { get } static var ColorListModeMask: NSColorPanelOptions { get } static var WheelModeMask: NSColorPanelOptions { get } static var CrayonModeMask: NSColorPanelOptions { get } static var AllModesMask: NSColorPanelOptions { get } }

    Objective-C

    enum { NSColorPanelGrayModeMask = 0x00000001, NSColorPanelRGBModeMask = 0x00000002, NSColorPanelCMYKModeMask = 0x00000004, NSColorPanelHSBModeMask = 0x00000008, NSColorPanelCustomPaletteModeMask = 0x00000010, NSColorPanelColorListModeMask = 0x00000020, NSColorPanelWheelModeMask = 0x00000040, NSColorPanelCrayonModeMask = 0x00000080, NSColorPanelAllModesMask = 0x0000ffff };

    Constants

    • GrayModeMask

      NSColorPanelGrayModeMask

      Grayscale-alpha.

      Available in OS X v10.0 and later.

    • RGBModeMask

      NSColorPanelRGBModeMask

      Red-green-blue.

      Available in OS X v10.0 and later.

    • CMYKModeMask

      NSColorPanelCMYKModeMask

      Cyan-yellow-magenta-black.

      Available in OS X v10.0 and later.

    • HSBModeMask

      NSColorPanelHSBModeMask

      Hue-saturation-brightness.

      Available in OS X v10.0 and later.

    • CustomPaletteModeMask

      NSColorPanelCustomPaletteModeMask

      Custom palette.

      Available in OS X v10.0 and later.

    • ColorListModeMask

      NSColorPanelColorListModeMask

      Custom color list.

      Available in OS X v10.0 and later.

    • WheelModeMask

      NSColorPanelWheelModeMask

      Color wheel.

      Available in OS X v10.0 and later.

    • CrayonModeMask

      NSColorPanelCrayonModeMask

      Crayons.

      Available in OS X v10.2 and later.

    • AllModesMask

      NSColorPanelAllModesMask

      All of the above.

      Available in OS X v10.0 and later.

    Import Statement

  • Specify the active color mode used when an application’s instance of NSColorPanel is masked for more than one color mode.

    Declaration

    Swift

    enum NSColorPanelMode : Int { case NSNoModeColorPanel case NSGrayModeColorPanel case NSRGBModeColorPanel case NSCMYKModeColorPanel case NSHSBModeColorPanel case NSCustomPaletteModeColorPanel case NSColorListModeColorPanel case NSWheelModeColorPanel case NSCrayonModeColorPanel }

    Objective-C

    enum { NSNoModeColorPanel = -1, NSGrayModeColorPanel = 0, NSRGBModeColorPanel = 1, NSCMYKModeColorPanel = 2, NSHSBModeColorPanel = 3, NSCustomPaletteModeColorPanel = 4, NSColorListModeColorPanel = 5, NSWheelModeColorPanel = 6, NSCrayonModeColorPanel = 7 };

    Constants

    • NSNoModeColorPanel

      NSNoModeColorPanel

      Indicates no color panel mode.

      Available in OS X version 10.5 and later.

    • NSGrayModeColorPanel

      NSGrayModeColorPanel

      Grayscale-alpha

      Available in OS X v10.0 and later.

    • NSRGBModeColorPanel

      NSRGBModeColorPanel

      Red-green-blue

      Available in OS X v10.0 and later.

    • NSCMYKModeColorPanel

      NSCMYKModeColorPanel

      Cyan-yellow-magenta-black

      Available in OS X v10.0 and later.

    • NSHSBModeColorPanel

      NSHSBModeColorPanel

      Hue-saturation-brightness

      Available in OS X v10.0 and later.

    • NSCustomPaletteModeColorPanel

      NSCustomPaletteModeColorPanel

      Custom palette

      Available in OS X v10.0 and later.

    • NSColorListModeColorPanel

      NSColorListModeColorPanel

      Custom color list

      Available in OS X v10.0 and later.

    • NSWheelModeColorPanel

      NSWheelModeColorPanel

      Color wheel

      Available in OS X v10.0 and later.

    • NSCrayonModeColorPanel

      NSCrayonModeColorPanel

      Crayons.

      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 in Color Programming Topics.

    Import Statement