PATH  Documentation > Mac OS X > Application Kit Reference: Objective-C

Table of Contents

NSColor


Inherits from:
NSResponder : NSObject
Conforms to:
NSCoding
NSCopying
NSObject (NSObject)
Declared in:
AppKit/NSColor.h



Class at a Glance


An NSColor object represents a color, which is defined in a color space, each point of which has a set of components (such as red, green, and blue) that uniquely define a color.

Principal Attributes


Creation



Various colorWith... and colorUsing... methods.
Preset colors: blackColor, blueColor, etc.

Commonly Used Methods



colorUsingColorSpaceName: Creates an NSColor in the specified color space.
set Sets the drawing color.


Class Description


An NSColor object represents color and sometimes opacity (alpha). By sending a set message to an NSColor instance, you set the color for the current drawing context. This causes subsequently drawn graphics to have the color represented by the NSColor instance.


Color Spaces


A color is defined in some particular color space. A color space consists of a set of dimensions-such as red, green, and blue in the case of RGB space. Each point in the space represents a unique color, and the point's location along each dimension is called a component. An individual color is usually specified by the numeric values of its components, which range from 0.0 to 1.0. For instance, a pure red is specified in RGB space by the component values 1.0, 0.0, and 0.0.

Some color spaces include an alpha component, which defines the color's opacity. An alpha value of 1.0 means completely opaque, and 0.0 means completely transparent. The alpha component is ignored when the color is used on a device that doesn't support alpha, such as a printer.

There are three kinds of color spaces in the Application Kit:

NSColors provided by the Application Kit use eight different color spaces, referred to by these global NSString variables:


Global Variable Color Space Description
NSDeviceCMYKColorSpace Cyan, magenta, yellow, black, and alpha components
NSDeviceWhiteColorSpace White and alpha components
NSDeviceRGBColorSpace Red, green, blue, and alpha componentsHue, saturation, brightness, and alpha components
NSCalibratedWhiteColorSpace White and alpha components
NSCalibratedRGBColorSpace Red, green, blue, and alpha componentsHue, saturation, brightness, and alpha components
NSNamedColorSpace Catalog name and color name components

Color spaces whose names start with "NSDevice" are device-dependent; those whose names start with "NSCalibrated" are device-independent.


Color Components


There's usually no need to retrieve the individual components of a color, but when needed, you can retrieve either a set of components (using such methods as getRed:green:blue:alpha:) or an individual component (using such methods as redComponent). However, it's illegal to ask an NSColor for components that aren't defined for its color space. You can identify the color space by sending a colorSpaceName message to the NSColor object. If you need to ask an NSColor for components that aren't in its color space (for instance, when you've gotten the color from the color panel), first convert the color to the appropriate color space using the colorUsingColorSpaceName: method. If the color is already in the specified color space, you get the same color back; otherwise you get a conversion that's usually lossy or that's correct only for the current device. You get back nil if the specified conversion can't be done.


Creating Subclasses


Subclasses of NSColor need to implement the colorSpaceName and set methods, as well as the methods that return the components for that color space and the methods in the NSCoding protocol. Some other methods-such as colorWithAlphaComponent:, isEqual:, and colorUsingColorSpaceName:device:-may also be implemented if they make sense for the color space. Mutable subclasses (if any) should additionally implement copyWithZone: to provide a true copy.


System Colors


NSColor has a number of methods which return "system" colors; colors that are controlled by user preferences. These colors-including controlColor, textColor, and selectedTextColor-should be used by developers who want to create custom controls or subclass existing controls while honoring the user's color preferences. System colors are implemented as named colors in a special color list named "System." To extract the components of a system color, you must use NSColor's colorUsingColorSpaceName: method to convert the color to a color space known to respond to the component accessor methods you need.

An NSSystemColorsDidChangeNotification is sent when the system colors have been changed (such as through a system control panel interface). If you have any non-system colors that depend on the system colors, you can change them when you receive this notification.




Adopted Protocols


NSCoding
- encodeWithCoder:
- initWithCoder:
NSCopying
- copyWithZone:


Method Types


Creating an NSColor object from Component Values
+ colorWithCalibratedHue:saturation:brightness:alpha:
+ colorWithCalibratedRed:green:blue:alpha:
+ colorWithCalibratedWhite:alpha:
+ colorWithCatalogName:colorName:
+ colorWithDeviceCyan:magenta:yellow:black:alpha:
+ colorWithDeviceHue:saturation:brightness:alpha:
+ colorWithDeviceRed:green:blue:alpha:
+ colorWithDeviceWhite:alpha:
Creating an NSColor With Preset Components
+ blackColor
+ blueColor
+ brownColor
+ clearColor
+ cyanColor
+ darkGrayColor
+ grayColor
+ greenColor
+ lightGrayColor
+ magentaColor
+ orangeColor
+ purpleColor
+ redColor
+ whiteColor
+ yellowColor
Creating a system color-an NSColor whose value is specified by user preferences
+ controlBackgroundColor
+ controlColor
+ controlHighlightColor
+ controlLightHighlightColor
+ controlShadowColor
+ controlDarkShadowColor
+ controlTextColor
+ disabledControlTextColor
+ gridColor
- headerColor
- headerTextColor
+ highlightColor
+ knobColor
+ scrollBarColor
+ selectedControlColor
+ selectedControlTextColor
+ selectedMenuItemColor
+ selectedMenuItemTextColor
+ selectedTextBackgroundColor
+ selectedTextColor
+ selectedKnobColor
+ shadowColor
+ textBackgroundColor
+ textColor
+ windowFrameColor
+ windowFrameTextColor
Ignoring Alpha Components
+ ignoresAlpha
+ setIgnoresAlpha:
Copying and Pasting
+ colorFromPasteboard:
- writeToPasteboard:
Retrieving a Set of Components
- getCyan:magenta:yellow:black:alpha:
- getHue:saturation:brightness:alpha:
- getRed:green:blue:alpha:
- getWhite:alpha:
Retrieving Individual Components
- alphaComponent
- blackComponent
- blueComponent
- brightnessComponent
- catalogNameComponent
- colorNameComponent
- cyanComponent
- greenComponent
- hueComponent
- localizedCatalogNameComponent
- localizedColorNameComponent
- magentaComponent
- redComponent
- saturationComponent
- whiteComponent
- yellowComponent
Converting to Another Color Space
- colorSpaceName
- colorUsingColorSpaceName:
- colorUsingColorSpaceName:device:
Changing the Color
- blendedColorWithFraction:ofColor:
- colorWithAlphaComponent:
- highlightWithLevel:
- shadowWithLevel:
Drawing
- drawSwatchInRect:
- set


Class Methods



blackColor

+ (NSColor *)blackColor

Returns an NSColor in NSCalibratedRGBColorSpace whose grayscale value is 0.0 and whose alpha value is 1.0.

See Also: - blackComponent



blueColor

+ (NSColor *)blueColor

Returns an NSColor in NSCalibratedRGBColorSpace whose RGB value is 0.0, 0.0, 1.0 and whose alpha value is 1.0.

See Also: - blueComponent



brownColor

+ (NSColor *)brownColor

Returns an NSColor in NSCalibratedRGBColorSpace whose RGB value is 0.6, 0.4, 0.2 and whose alpha value is 1.0.

clearColor

+ (NSColor *)clearColor

Returns an NSColor in NSCalibratedWhiteColorSpace whose grayscale and alpha values are both 0.0.

colorFromPasteboard:

+ (NSColor *)colorFromPasteboard:(NSPasteboard *)pasteBoard

Returns the NSColor currently on the pasteboard, or nil if the pasteboard doesn't contain color data. The returned color's alpha component is set to 1.0 if ignoresAlpha returns YES.

See Also: - writeToPasteboard:



colorWithCalibratedHue:saturation:brightness:alpha:

+ (NSColor *)colorWithCalibratedHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha

Creates and returns an NSColor whose color space is NSCalibratedRGBColorSpace, whose opacity value is alpha, and whose components in HSB space would be hue, saturation, and brightness. (Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.)

See Also: + colorWithCalibratedRed:green:blue:alpha:, + colorWithDeviceHue:saturation:brightness:alpha:, - getHue:saturation:brightness:alpha:



colorWithCalibratedRed:green:blue:alpha:

+ (NSColor *)colorWithCalibratedRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha

Creates and returns an NSColor whose color space is NSCalibratedRGBColorSpace, whose opacity value is alpha, and whose RGB components are red, green, and blue. (Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.)

See Also: + colorWithCalibratedHue:saturation:brightness:alpha:, + colorWithDeviceRed:green:blue:alpha:, - getRed:green:blue:alpha:



colorWithCalibratedWhite:alpha:

+ (NSColor *)colorWithCalibratedWhite:(float)white alpha:(float)alpha

Creates and returns an NSColor whose color space is NSCalibratedWhiteColorSpace, whose opacity value is alpha, and whose grayscale value is white. (Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.)

See Also: + colorWithDeviceWhite:alpha:, - getWhite:alpha:



colorWithCatalogName:colorName:

+ (NSColor *)colorWithCatalogName:(NSString *)listName colorName:(NSString *)colorName

Creates and returns an NSColor whose color space is NSNamedColorSpace, by finding the color named colorName in the catalog named listName, which may be a standard catalog.

See Also: - catalogNameComponent, - colorNameComponent, - localizedCatalogNameComponent



colorWithDeviceCyan:magenta:yellow:black:alpha:

+ (NSColor *)colorWithDeviceCyan:(float)cyan magenta:(float)magenta yellow:(float)yellow black:(float)black alpha:(float)alpha

Creates and returns an NSColor whose color space is NSDeviceCMYKColorSpace, whose opacity value is alpha, and whose CMYK components are cyan, magenta, yellow, and black. (Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.) In PostScript, this colorspace corresponds directly to the device-dependent operator setcmykcolor.

See Also: - getCyan:magenta:yellow:black:alpha:



colorWithDeviceHue:saturation:brightness:alpha:

+ (NSColor *)colorWithDeviceHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha

Creates and returns an NSColor whose color space is NSDeviceRGBColorSpace, whose opacity value is alpha, and whose components in HSB space would be hue, saturation, and brightness. (Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.) In PostScript, this colorspace corresponds directly to the device-dependent operator setrgbcolor.

See Also: + colorWithCalibratedHue:saturation:brightness:alpha:, + colorWithDeviceRed:green:blue:alpha:, - getHue:saturation:brightness:alpha:



colorWithDeviceRed:green:blue:alpha:

+ (NSColor *)colorWithDeviceRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha

Creates and returns an NSColor whose color space is NSDeviceRGBColorSpace, whose opacity value is alpha, and whose RGB components are red, green, and blue. (Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.) In PostScript, this colorspace corresponds directly to the device-dependent operator setrgbcolor.

See Also: + colorWithCalibratedRed:green:blue:alpha:, + colorWithDeviceHue:saturation:brightness:alpha:, - getRed:green:blue:alpha:



colorWithDeviceWhite:alpha:

+ (NSColor *)colorWithDeviceWhite:(float)white alpha:(float)alpha

Creates and returns an NSColor whose color space is NSDeviceWhiteColorSpace, whose opacity value is alpha, and whose grayscale value is white. (Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.) In PostScript, this colorspace corresponds directly to the device-dependent operator setgray.

See Also: + colorWithCalibratedWhite:alpha:, - getWhite:alpha:



controlBackgroundColor

+ (NSColor *)controlBackgroundColor

Returns the system color used for the background of large controls such as browsers, table views and clip views. By default, this color is light gray. For general information on system colors, see "System Colors" .

controlColor

+ (NSColor *)controlColor

Returns the system color used for the flat surfaces of a control. By default, the control color is light gray. A control's beveled edges, which set it in relief, are drawn in the colors returned by controlShadowColor, controlDarkShadowColor, controlHighlightColor and controlLightHighlightColor. When a control is selected-that is, clicked or dragged-it changes to the color returned by selectedControlColor.

The return value of controlColor is also the system color used for window backgrounds. For general information about system colors, see "System Colors" .



controlDarkShadowColor

+ (NSColor *)controlDarkShadowColor

Returns the system color used for the dark edge of the shadow dropped from controls. Controls are displayed as though they were lit from the upper left. Two dark borders, representing shadows, run along the bottom and right. controlDarkShadowColor returns the color of the outer, darker border. By default, this color is black. For general information about system colors, see "System Colors" .

See Also: + controlShadowColor



controlHighlightColor

+ (NSColor *)controlHighlightColor

Returns the system color used for the highlighted bezels of controls. Controls are displayed as though they were lit from the upper left. Two light borders, representing reflections from the light source, run along the top and left. controlHighlightColor returns the color of the inner, duller border. By default, this color is light gray. For general information about system colors, see "System Colors" .

See Also: + controlLightHighlightColor



controlLightHighlightColor

+ (NSColor *)controlLightHighlightColor

Returns the system color used for light highlights in controls. Controls are displayed as though they were lit from the upper left. Two light borders, representing reflections from the light source, run along the top and left. controlLightHighlightColor returns the color of the outer, brighter border. By default, this color is white. For general information about system colors, see "System Colors" .

See Also: + controlHighlightColor



controlShadowColor

+ (NSColor *)controlShadowColor

Returns the system color used for the shadows dropped from controls. Controls are displayed as though they were lit from the upper left. Two dark borders, representing shadows, run along the bottom and right. controlShadowColor returns the color of the inner, lighter border. By default, this color is dark gray. For general information about system colors, see "System Colors" .

See Also: + controlDarkShadowColor



controlTextColor

+ (NSColor *)controlTextColor

Returns the system color used for text on controls that aren't disabled. By default, the text color is black. For general information about system colors, see "System Colors" .

See Also: + disabledControlTextColor



cyanColor

+ (NSColor *)cyanColor

Returns an NSColor in NSCalibratedRGBColorSpace whose RGB value is 0.0, 1.0, 1.0 and whose alpha value is 1.0.

See Also: - cyanComponent



darkGrayColor

+ (NSColor *)darkGrayColor

Returns an NSColor in NSCalibratedRGBColorSpace whose grayscale value is 1/3 and whose alpha value is 1.0.

See Also: + lightGrayColor, + grayColor



disabledControlTextColor

+ (NSColor *)disabledControlTextColor

Returns the system color used for text on disabled controls. By default, the text color is dark gray. For general information about system colors, see "System Colors" .

See Also: + controlTextColor



grayColor

+ (NSColor *)grayColor

Returns an NSColor in NSCalibratedWhiteColorSpace whose grayscale value is 0.5 and whose alpha value is 1.0.

See Also: + lightGrayColor, + darkGrayColor



greenColor

+ (NSColor *)greenColor

Returns an NSColor in NSCalibratedRGBColorSpace whose RGB value is 0.0, 1.0, 0.0 and whose alpha value is 1.0.

See Also: - greenComponent



gridColor

+ (NSColor *)gridColor

Returns the system color used for the optional gridlines in, for example, a table view. By default, this color is gray. For general information about system colors, see "System Colors" .

headerColor

+ (NSColor *)headerColor

Returns the system color used as the background color for header cells in table views and outline views. For general information about system colors, see "System Colors" .

headerTextColor

+ (NSColor *)headerColor

Returns the system color used for text in header cells in table views and outline views. For general information about system colors, see "System Colors" .

highlightColor

+ (NSColor *)highlightColor

Returns the system color that represents the virtual light source on the screen. By default, this color is white. This method is invoked by the highlightWithLevel: method. For general information about system colors, see "System Colors" .

See Also: - highlightWithLevel:



ignoresAlpha

+ (BOOL)ignoresAlpha

Returns YES if the application doesn't support alpha. This value is consulted when an application imports alpha (through color dragging, for instance). The value determines whether the color panel has an opacity slider. This value is YES by default, indicating that the opacity components of imported colors will be set to 1.0. If an application wants alpha, it can invoke the setIgnoresAlpha: method with a parameter of NO.

See Also: + setIgnoresAlpha:, - alphaComponent



keyboardFocusIndicatorColor

+ (NSColor *)keyboardFocusIndicatorColor

Description forthcoming.

knobColor

+ (NSColor *)knobColor

Returns the system color used for the flat surface of a slider knob that hasn't been selected. By default, this color is light blue. The knob's beveled edges, which set it in relief, are drawn in highlighted and shadowed versions of the face color. When a knob is selected, its color changes to selectedKnobColor. For general information about system colors, see "System Colors" .

lightGrayColor

+ (NSColor *)lightGrayColor

Returns an NSColor in NSCalibratedRGBColorSpace whose grayscale value is 2/3 and whose alpha value is 1.0.

See Also: + grayColor, + darkGrayColor



magentaColor

+ (NSColor *)magentaColor

Returns an NSColor in NSCalibratedRGBColorSpace whose RGB value is 1.0, 0.0, 1.0 and whose alpha value is 1.0.

See Also: - magentaComponent



orangeColor

+ (NSColor *)orangeColor

Returns an NSColor in NSCalibratedRGBColorSpace whose RGB value is 1.0, 0.5, 0.0 and whose alpha value is 1.0.

purpleColor

+ (NSColor *)purpleColor

Returns an NSColor in NSCalibratedRGBColorSpace whose RGB value is 0.5, 0.0, 0.5 and whose alpha value is 1.0.

redColor

+ (NSColor *)redColor

Returns an NSColor in NSCalibratedRGBColorSpace whose RGB value is 1.0, 0.0, 0.0 and whose alpha value is 1.0.

See Also: - redComponent



scrollBarColor

+ (NSColor *)scrollBarColor

Returns the system color used for scroll "bars"-that is, for the groove in which a scroller's knob moves. By default, this color is gray. For general information about system colors, see "System Colors" .

selectedControlColor

+ (NSColor *)selectedControlColor

Returns the system color used for the face of a selected control-a control being clicked or dragged. By default, this color is white. For general information about system colors, see "System Colors" .

See Also: + selectedControlTextColor



selectedControlTextColor

+ (NSColor *)selectedControlTextColor

Returns the system color used for text in a selected control-a control being clicked or dragged. By default, this color is black. For general information about system colors, see "System Colors" .

See Also: + selectedControlColor



selectedKnobColor

+ (NSColor *)selectedKnobColor

Returns the system color used for the slider knob when it is selected-that is, dragged. By default, this color is light blue. For general information about system colors, see "System Colors" .

See Also: + knobColor



selectedMenuItemColor

+ (NSColor *)selectedMenuItemColor

Returns the system color used for the face of selected menu items. By default, this color is white. For general information about system colors, see "System Colors" .

See Also: + selectedMenuItemTextColor



selectedMenuItemTextColor

+ (NSColor *)selectedMenuItemTextColor

Returns the system color used for the text in menu items. By default, this color is black. For general information about system colors, see "System Colors" .

See Also: + selectedMenuItemColor



selectedTextBackgroundColor

+ (NSColor *)selectedTextBackgroundColor

Returns the system color used for the background of selected text. By default, this color is light gray. For general information about system colors, see "System Colors" .

See Also: + selectedTextColor



selectedTextColor

+ (NSColor *)selectedTextColor

Returns the system color used for selected text. By default, this color is black. For general information about system colors, see "System Colors" .

See Also: + selectedTextBackgroundColor



setIgnoresAlpha:

+ (void)setIgnoresAlpha:(BOOL)flag

If flag is YES, the application won't support alpha. In this case, no opacity slider is displayed in the color panel, and colors dragged in or pasted have their alpha values set to 1.0. By default, applications ignore alpha. Applications that need to import alpha can invoke this method with flag set to NO and explicitly make colors opaque in cases where it matters to them.

See Also: + ignoresAlpha, - alphaComponent



shadowColor

+ (NSColor *)shadowColor

Returns the system color that represents the virtual shadows cast by raised objects on the screen. This method is invoked by shadowWithLevel:. By default, the color it returns is black. For general information about system colors, see "System Colors" .

See Also: - shadowWithLevel:



textBackgroundColor

+ (NSColor *)textBackgroundColor

Returns the system color used for the text background. By default, this color is white. When text is selected, its background color changes to the return value of selectedTextBackgroundColor. For general information about system colors, see "System Colors" .

See Also: + textColor



textColor

+ (NSColor *)textColor

Returns the system color used for text. By default, this color is black. When text is selected, its background color changes to the return value of selectedTextColor. For general information about system colors, see "System Colors" .

See Also: + textBackgroundColor



whiteColor

+ (NSColor *)whiteColor

Returns an NSColor in NSCalibratedWhiteColorSpace whose grayscale and alpha values are both 1.0.

See Also: - whiteComponent



windowFrameColor

+ (NSColor *)windowFrameColor

Returns the system color used for window frames, except for their text. By default, this color is gray. For general information about system colors, see "System Colors" .

See Also: + windowFrameTextColor



windowFrameTextColor

+ (NSColor *)windowFrameTextColor

Returns the system color used for the text in window frames. By default, this color is black. For general information about system colors, see "System Colors" .

See Also: + windowFrameColor



yellowColor

+ (NSColor *)yellowColor

Returns an NSColor in NSCalibratedRGBColorSpace whose RGB value is 1.0, 1.0, 0.0 and whose alpha value is 1.0.

See Also: - yellowComponent




Instance Methods



alphaComponent

- (float)alphaComponent

Returns the receiver's alpha (opacity) component. Returns 1.0 (opaque) if the receiver has no alpha component.

See Also: - getCyan:magenta:yellow:black:alpha:, - getHue:saturation:brightness:alpha:, - getRed:green:blue:alpha:, - getWhite:alpha:



blackComponent

- (float)blackComponent

Returns the receiver's black component. Raises an exception if the receiver isn't a CMYK color.

See Also: - getCyan:magenta:yellow:black:alpha:



blendedColorWithFraction:ofColor:

- (NSColor *)blendedColorWithFraction:(float)fraction fColor:(NSColor *)color

Creates and returns an NSColor in NSCalibratedRGBColorSpace whose component values are a weighted sum of the receiver's and color's. The method converts color and a copy of the receiver to RGB, and then sets each component of the returned color to fraction of color's value plus 1 - fraction of the receiver's. Returns nil if the colors can't be converted to NSCalibratedRGBColorSpace.

blueComponent

- (float)blueComponent

Returns the receiver's blue component. Raises an exception if the receiver isn't an RGB color.

See Also: - getRed:green:blue:alpha:



brightnessComponent

- (float)brightnessComponent

Returns the brightness component of the HSB color equivalent to the receiver. Raisesan exception if the receiver isn't an RGB color.

See Also: - getHue:saturation:brightness:alpha:



catalogNameComponent

- (NSString *)catalogNameComponent

Returns the name of the catalog containing the receiver's name. Raises an exception if the receiver's color space isn't NSNamedColorSpace.

See Also: + colorWithCatalogName:colorName:, - colorNameComponent, - localizedCatalogNameComponent



colorNameComponent

- (NSString *)colorNameComponent

Returns the receiver's name. Raises an exception if the receiver's color space isn't NSNamedColorSpace.

See Also: + colorWithCatalogName:colorName:, - catalogNameComponent, - localizedCatalogNameComponent



colorSpaceName

- (NSString *)colorSpaceName

Returns the name of the receiver's color space. This method should be implemented in subclasses of NSColor.

See Also: - colorUsingColorSpaceName:, - colorUsingColorSpaceName:device:



colorUsingColorSpaceName:

- (NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace

Creates and returns an NSColor whose color is the same as the receiver's, except that the new NSColor is in the color space named colorSpace. If colorSpace is nil, the most appropriate color space is used.

Returns nil if the specified conversion cannot be done.

See Also: - colorSpaceName



colorUsingColorSpaceName:device:

- (NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace device:(NSDictionary *)deviceDescription

Creates and returns an NSColor whose color is the same as the receiver's, except that the new NSColor is in the color space named colorSpace and is specific to the device described by deviceDescription. Device descriptions can be obtained from windows, screens, and printers with the deviceDescription method. If colorSpace is nil, the most appropriate color space is used.

If deviceDescription is nil, the current device (as obtained from the currently lockFocus'ed view's window or, if printing, the current printer) is used.

Returns nil if the specified conversion cannot be done.

See Also: - colorSpaceName, - colorUsingColorSpaceName:



colorWithAlphaComponent:

- (NSColor *)colorWithAlphaComponent:(float)alpha

Creates and returns an NSColor that has the same color space and component values as the receiver, except its alpha component is alpha. If the receiver's color space doesn't include an alpha component, the receiver is returned. A subclass with explicit opacity components should override this method to return a color with the specified alpha.

See Also: - alphaComponent, - blendedColorWithFraction:ofColor:



cyanComponent

- (float)cyanComponent

Returns the receiver's cyan component. Raises an exception if the receiver isn't a CMYK color.

See Also: - getCyan:magenta:yellow:black:alpha:



drawSwatchInRect:

- (void)drawSwatchInRect:(NSRect)rect

Draws the current color in the rectangle rect. Subclasses adorn the rectangle in some manner to indicate the type of color. This method is invoked by color wells, swatches, and other user-interface objects that need to display colors.

getCyan:magenta:yellow:black:alpha:

- (void)getCyan:(float *)cyan magenta:(float *)magenta yellow:(float *)yellow black:(float *)black alpha:(float *)alpha

Returns the receiver's CMYK and alpha values in the respective arguments. If nil is passed in as an argument, the method doesn't set that value. Raises an exception if the receiver isn't a CMYK color.

See Also: - alphaComponent, - blackComponent, - cyanComponent, - magentaComponent, - yellowComponent



getHue:saturation:brightness:alpha:

- (void)getHue:(float *)hue saturation:(float *)saturation brightness:(float *)brightness alpha:(float *)alpha

Returns the receiver's HSB and alpha values in the respective arguments. If nil is passed in as an argument, the method doesn't set that value. Raises an exception if the receiver isn't an RGB color.

See Also: - alphaComponent, - brightnessComponent, - hueComponent, - saturationComponent



getRed:green:blue:alpha:

- (void)getRed:(float *)red green:(float *)green blue:(float *)blue alpha:(float *)alpha

Returns the receiver's RGB and alpha values in the respective arguments. If nil is passed in as an argument, the method doesn't set that value. Raises an exception if the receiver isn't an RGB color.

See Also: - alphaComponent, - blueComponent, - greenComponent, - redComponent



getWhite:alpha:

- (void)getWhite:(float *)white alpha:(float *)alpha

Returns the receiver's grayscale and alpha values in the respective arguments. If nil is passed in as an argument, the method doesn't set that value. Raises an exception if the receiver isn't a grayscale color.

See Also: - alphaComponent, - whiteComponent



greenComponent

- (float)greenComponent

Returns the receiver's green component. Raises an exception if the receiver isn't an RGB color.

See Also: - getRed:green:blue:alpha:



highlightWithLevel:

- (NSColor *)highlightWithLevel:(float)highlightLevel

Returns an NSColor in NSCalibratedRGBColorSpace that represents a blend between the receiver and the highlight color returned by highlightColor. The highlight color's contribution to the blend depends on highlightLevel, which should be a number between 0.0 and 1.0. (A highlightLevel below 0.0 is interpreted as 0.0 (the receiver); a highlightLevel above 1.0 is interpreted as 1.0 (highlightLevel).)

Returns nil if the colors can't be converted to NSCalibratedRGBColorSpace. Invoke this method when you want to brighten the receiving NSColor for use in highlights.

See Also: - shadowWithLevel:



hueComponent

- (float)hueComponent

Returns the hue component of the HSB color equivalent to the receiver. Raises an exception if the receiver isn't an RGB color.

See Also: - getHue:saturation:brightness:alpha:



localizedCatalogNameComponent

- (NSString *)localizedCatalogNameComponent

Like catalogNameComponent, but returns a localized string. This string may be displayed in user-interface items like color pickers.

See Also: + colorWithCatalogName:colorName:, - colorNameComponent



localizedColorNameComponent

- (NSString *)localizedColorNameComponent

Like colorNameComponent, but returns a localized string. This string may be displayed in user-interface items like color pickers.

See Also: + colorWithCatalogName:colorName:, - catalogNameComponent, - colorNameComponent, - localizedCatalogNameComponent



magentaComponent

- (float)magentaComponent

Returns the receiver's magenta component. Raises an exception if the receiver isn't a CMYK color.

See Also: - getCyan:magenta:yellow:black:alpha:



redComponent

- (float)redComponent

Returns the receiver's red component. Raises an exception if the receiver isn't an RGB color.

See Also: - getRed:green:blue:alpha:



saturationComponent

- (float)saturationComponent

Returns the saturation component of the HSB color equivalent to the receiver. Raises an exception if the receiver isn't an RGB color.

See Also: - getHue:saturation:brightness:alpha:



set

- (void)set

Sets the color of subsequent drawing to the color that the receiver represents. If the application is drawing to the screen rather than printing, this method also sets the current drawing context's alpha value to the value returned by alphaComponent; if the color doesn't know about alpha, it's set to 1.0. This method should be implemented in subclasses.

shadowWithLevel:

- (NSColor *)shadowWithLevel:(float)shadowLevel

Returns an NSColor in NSCalibratedRGBColorSpace that represents a blend between the receiver and the shadow color returned by shadowColor. The shadow color's contribution to the blend depends on shadowLevel, which should be a number between 0.0 and 1.0. (A shadowLevel below 0.0 is interpreted as 0.0 (the receiver); a shadowLevel above 1.0 is interpreted as 1.0 (shadowLevel).)

Returns nil if the colors can't be converted to NSCalibratedRGBColorSpace. Invoke this method when you want to darken the receiving NSColor for use in shadows.

See Also: - highlightWithLevel:



whiteComponent

- (float)whiteComponent

Returns the receiver's white component. Raises an exception if the receiver isn't a grayscale color.

See Also: - getWhite:alpha:



writeToPasteboard:

- (void)writeToPasteboard:(NSPasteboard *)pasteBoard

Writes the receiver's data to the pasteboard, unless the pasteboard doesn't support color data (in which case the method does nothing).

See Also: + colorFromPasteboard:



yellowComponent

- (float)yellowComponent

Returns the receiver's yellow component. Raises an exception if the receiver isn't a CMYK color.

See Also: - getCyan:magenta:yellow:black:alpha:




Notifications


NSSystemColorsDidChangeNotification

Sent when the system colors have been changed (such as through a system control panel interface).

This notification contains no notification object and no userInfo dictionary.



Table of Contents