A standard user interface for selecting color in an app.


NSColorPanel provides a number of standard color selection modes and, with the NSColorPickingDefault and NSColorPickingCustom protocols, allows an app to add its own color selection modes. It also allows the user to save swatches containing frequently used colors.


Obtaining the Shared Color-Panel Object

class var shared: NSColorPanel

Returns the shared NSColorPanel instance, creating it if necessary.

class var sharedColorPanelExists: Bool

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

Configuring the Color Panel

var accessoryView: NSView?

The accessory view.

var isContinuous: Bool

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

var mode: NSColorPanel.Mode

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

func setAction(Selector?)

Sets the color panel's action message.

func setTarget(Any?)

Sets the target of the receiver.

var showsAlpha: Bool

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

Managing Color Lists

func attachColorList(NSColorList)

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.

func detachColorList(NSColorList)

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.

Setting Color Picker Modes

class func setPickerMask(NSColorPanel.Options)

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

class func setPickerMode(NSColorPanel.Mode)

Specifies the color panel’s initial picker.

Setting Color

class func dragColor(NSColor, with: NSEvent, from: NSView)

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

var color: NSColor

The color of the receiver.

Getting Color Information

var alpha: CGFloat

The receiver’s current alpha value based on its opacity slider.

Responding to a Color Change

func changeColor(Any?)

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


Color Picker Mode Masks

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

enum NSColorPanel.Mode

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

Color Panel Modes

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


class let colorDidChangeNotification: NSNotification.Name

Posted when the color of the NSColorPanel is set, as when NSColorPanel is invoked.


Inherits From

See Also

Color Panels

protocol NSColorPickingCustom

A set of methods that provides a way to add color pickers—custom user interfaces for color selection—to an app’s color panel.

protocol NSColorPickingDefault

A set of methods that provides basic behavior for a color picker.

class NSColorPicker

An abstract superclass that implements the NSColorPickingDefault protocol.