NSColor 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 | 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
Color space
Color components
Creation
Various
colorWith...andcolorUsing...methods.Preset colors:
blackColor,blueColor, and so on.
Commonly Used Methods
colorUsingColorSpaceName:Creates an
NSColorinstance in the specified color space.setSets the drawing color.
Overview
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. Setting the color causes subsequently drawn graphics to have the color represented by the NSColor instance.
It is invalid to use an accessor method related to components of a particular color space on an NSColor object that is not in that color space. For example, methods such as redComponent and getRed:green:blue:alpha: work on color objects in the calibrated and device RGB color spaces. If you send such a message to an NSColor object in the CMYK color space, an exception is raised. Further, the methods getComponents: and numberOfComponents work in color spaces that have individual components. Thus they return the components of NSColor objects as individual floating-point values regardless of whether they’re based on NSColorSpace objects or named color spaces. However, older component-fetching methods such as redComponent and getRed:green:blue:alpha: are only effective on NSColor objects based on named color spaces.
If you have an NSColor object in an unknown color space and you want to extract its components, you should first convert the color object to a known color space before using the component accessor methods of that color space.
Adopted Protocols
Tasks
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: -
+ colorWithCIColor: -
+ colorWithColorSpace:components:count: -
+ colorWithSRGBRed:green:blue:alpha: -
+ colorWithGenericGamma22White:alpha:
Creating an NSColor with Preset Components
-
+ blackColor -
+ blueColor -
+ brownColor -
+ clearColor -
+ cyanColor -
+ darkGrayColor -
+ grayColor -
+ greenColor -
+ lightGrayColor -
+ magentaColor -
+ orangeColor -
+ purpleColor -
+ redColor -
+ whiteColor -
+ yellowColor
Working with Pattern Images
Creating a System Color—an NSColor Whose Value Is Specified by User Preferences
-
+ alternateSelectedControlColor -
+ alternateSelectedControlTextColor -
+ colorForControlTint: -
+ controlBackgroundColor -
+ controlColor -
+ controlAlternatingRowBackgroundColors -
+ controlHighlightColor -
+ controlLightHighlightColor -
+ controlShadowColor -
+ controlDarkShadowColor -
+ controlTextColor -
+ currentControlTint -
+ disabledControlTextColor -
+ gridColor -
+ headerColor -
+ headerTextColor -
+ highlightColor -
+ keyboardFocusIndicatorColor -
+ knobColor -
+ scrollBarColor -
+ secondarySelectedControlColor -
+ selectedControlColor -
+ selectedControlTextColor -
+ selectedMenuItemColor -
+ selectedMenuItemTextColor -
+ selectedTextBackgroundColor -
+ selectedTextColor -
+ selectedKnobColor -
+ shadowColor -
+ textBackgroundColor -
+ textColor -
+ windowBackgroundColor -
+ windowFrameColor -
+ windowFrameTextColor -
+ underPageBackgroundColor
Ignoring Alpha Components
Copying and Pasting
Retrieving a Set of Components
-
– getCyan:magenta:yellow:black:alpha: -
– getHue:saturation:brightness:alpha: -
– getRed:green:blue:alpha: -
– getWhite:alpha: -
– getComponents: -
– numberOfComponents
Retrieving Individual Components
-
– alphaComponent -
– blackComponent -
– blueComponent -
– brightnessComponent -
– catalogNameComponent -
– colorNameComponent -
– cyanComponent -
– greenComponent -
– hueComponent -
– localizedCatalogNameComponent -
– localizedColorNameComponent -
– magentaComponent -
– redComponent -
– saturationComponent -
– whiteComponent -
– yellowComponent
Working with the Color Space
-
– colorSpaceName -
– colorUsingColorSpaceName: -
– colorUsingColorSpaceName:device: -
– colorSpace -
– colorUsingColorSpace:
Changing the Color
-
– blendedColorWithFraction:ofColor: -
– colorWithAlphaComponent: -
– highlightWithLevel: -
– shadowWithLevel:
Converting Colors Between CGColors
Drawing
Class Methods
alternateSelectedControlColor
Returns the system color used for the face of a selected control.
Return Value
The system color used for the face of a selected control—a control being clicked or dragged. This color can be used where iApp-like highlighting is desired. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.2 and later.
Declared In
NSColor.halternateSelectedControlTextColor
Returns the system color used for text in a selected control.
Return Value
The system color used for text in a selected control—a control being clicked or dragged. This color can be used where iApp-like highlighting is desired. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.2 and later.
Declared In
NSColor.hblackColor
Returns an NSColor object whose grayscale value is 0.0 and whose alpha value is 1.0.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hblueColor
Returns an NSColor object whose RGB value is 0.0, 0.0, 1.0 and whose alpha value is 1.0.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hbrownColor
Returns an NSColor object whose RGB value is 0.6, 0.4, 0.2 and whose alpha value is 1.0.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hclearColor
Returns an NSColor object whose grayscale and alpha values are both 0.0.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hcolorForControlTint:
Returns the NSColor object specified by the given control tint.
Parameters
- controlTint
The control tint for which to return an
NSColorobject. This is one of the tint settings. For more on control tints, see “Using the System Control Tint”.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hcolorFromPasteboard:
Returns the NSColor currently on the given pasteboard.
Parameters
- pasteBoard
The pasteboard from which to return the color.
Return Value
The color currently on the pasteboard or nil if pasteBoard doesn’t contain color data. The returned color’s alpha component is set to 1.0 if ignoresAlpha returns YES.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hcolorWithCalibratedHue:saturation:brightness:alpha:
Creates and returns an NSColor object using the given opacity and HSB color space components.
Parameters
- hue
The hue component of the color object in the HSB color space.
- saturation
The saturation component of the color object in the HSB color space.
- brightness
The brightness (or value) component of the color object in the HSB color space.
- alpha
The opacity value of the color object,
Return Value
The color object.
Discussion
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hcolorWithCalibratedRed:green:blue:alpha:
Creates and returns an NSColor object using the given opacity and RGB components.
Parameters
- red
The red component of the color object.
- green
The green component of the color object.
- blue
The blue component of the color object.
- alpha
The opacity value of the color object.
Return Value
The color object.
Discussion
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hcolorWithCalibratedWhite:alpha:
Creates and returns an NSColor object using the given opacity and grayscale value.
Parameters
- white
The grayscale value of the color object.
- alpha
The opacity value of the color object.
Return Value
The color object.
Discussion
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hcolorWithCatalogName:colorName:
Creates and returns an NSColor object by finding the color with the specified name in the given catalog.
Parameters
- listName
The name of the catalog in which to find the specified color; this may be a standard catalog.
- colorName
The name of the color. Note that the color must be defined in the named color space to retrieve it with this method.
Return Value
The color object.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hcolorWithCGColor:
Creates and returns a new color using the specified CGColor.
Parameters
- cgColor
The
CGColor.
Return Value
An NSColor instance.
Discussion
This may return nil.
Availability
- Available in OS X v10.8 and later.
Declared In
NSColor.hcolorWithCIColor:
Converts a Core Image color object to its NSColor equivalent.
Parameters
- color
The Core Image color to convert.
Return Value
The NSColor object corresponding to the specified Core Image color.
Discussion
The method raises if the color space and components associated with color are nil or invalid.
Availability
- Available in OS X v10.4 and later.
Declared In
NSColor.hcolorWithColorSpace:components:count:
Returns an NSColor object created from the specified components of the given color space.
Parameters
- space
An
NSColorSpaceobject representing a color space. The method raises if this isnil.- components
An array of the components in the specified color space to use to create the
NSColorobject. The order of these components is determined by the color-space profile, with the alpha component always last. (If you want the created color to be opaque, specify 1.0 for the alpha component.)- numberOfComponents
The number of components in the
componentsarray. This should match the number dictated by the specified color space plus one for alpha. This method raises an exception if they do not match.
Return Value
The color object. If space represents a color space that cannot cannot be used with NSColor objects—for example, a “pattern” color space—the method returns nil.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSColor.hcolorWithDeviceCyan:magenta:yellow:black:alpha:
Creates and returns an NSColor object using the given opacity value and CMYK components.
Parameters
- cyan
The cyan component of the color object.
- magenta
The magenta component of the color object.
- yellow
The yellow component of the color object.
- black
The black component of the color object.
- alpha
The opacity value of the color object.
Return Value
The color object.
Discussion
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hcolorWithDeviceHue:saturation:brightness:alpha:
Creates and returns an NSColor object using the given opacity value and HSB color space components.
Parameters
- hue
The hue component of the color object.
- saturation
The saturation component of the color object.
- brightness
The brightness component of the color object.
- alpha
The opacity value of the color object.
Return Value
The color object.
Discussion
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hcolorWithDeviceRed:green:blue:alpha:
Creates and returns an NSColor object using the given opacity value and RGB components.
Parameters
- red
The red component of the color object.
- green
The green component of the color object.
- blue
The blue component of the color object.
- alpha
The opacity value of the color object.
Return Value
The color object.
Discussion
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hcolorWithDeviceWhite:alpha:
Creates and returns an NSColor object using the given opacity and grayscale values.
Parameters
- white
The grayscale value of the color object.
- alpha
The opacity value of the color object.
Return Value
The color object.
Discussion
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hcolorWithGenericGamma22White:alpha:
Returns an color created with the specified white and alpha values in the GenericGamma22 colorspace.
Parameters
- white
The white value of the color object.
- alpha
The opacity value of the color object.
Return Value
The color object.
Discussion
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSColor.hcolorWithPatternImage:
Creates and returns an NSColor object that uses the specified image pattern.
Parameters
- image
The image to use as the pattern for the color object. The image is tiled starting at the bottom of the window. The image is not scaled.
Return Value
The NSColor object. This color object is autoreleased.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hcolorWithSRGBRed:green:blue:alpha:
Returns a color created from the specified components in the sRGB colorspace.
Parameters
- red
The red component of the color object.
- green
The green component of the color object.
- blue
The blue component of the color object.
- alpha
The opacity value of the color object.
Return Value
The color object.
Discussion
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSColor.hcontrolAlternatingRowBackgroundColors
Returns an array containing the system specified background colors for alternating rows in tables and lists.
Return Value
An array of NSColor objects specifying the system colors used for rows in tables and lists. You should not assume the array will contain only two colors. For general information on system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.3 and later.
Declared In
NSColor.hcontrolBackgroundColor
Returns the system color used for the background of large controls.
Return Value
The system color used for the background of large controls such as browsers, table views, and clip views. For general information on system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hcontrolColor
Returns the system color used for the flat surfaces of a control.
Return Value
The system color used for the flat surfaces of a control. By default, the control color is a pattern color that will draw the ruled lines for the window background, which is the same as returned by windowBackgroundColor.
If you use controlColor assuming that it is a solid, you may have an incorrect appearance. You should use lightGrayColor in its place.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hcontrolDarkShadowColor
Returns the system color used for the dark edge of the shadow dropped from controls.
Return Value
Of the two dark borders that run along the bottom and right of controls, representing shadows, the color of the outer, darker border. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hcontrolHighlightColor
Returns the system color used for the highlighted bezels of controls.
Return Value
Of the two light borders that run along the top and left of controls, representing reflections from a light source in the upper left, the color of the inner, duller border. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hcontrolLightHighlightColor
Returns the system color used for light highlights in controls.
Return Value
Of the two light borders that run along the top and left of controls, representing reflections from a light source in the upper left, the color of the outer, brighter border. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hcontrolShadowColor
Returns the system color used for the shadows dropped from controls.
Return Value
Of the two dark borders that run along the bottom and right of controls, representing shadows, the color of the inner, lighter border. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hcontrolTextColor
Returns the system color used for text on controls that aren’t disabled.
Return Value
The color used for text on enabled controls. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hcurrentControlTint
Returns the current system control tint.
Return Value
The current system control tint.
Discussion
An application can register for the NSControlTintDidChangeNotification notification to be notified of changes to the system control tint.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSColor.hcyanColor
Returns an NSColor object whose RGB value is 0.0, 1.0, 1.0 and whose alpha value is 1.0.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hdarkGrayColor
Returns an NSColor object whose grayscale value is 1/3 and whose alpha value is 1.0.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hdisabledControlTextColor
Returns the system color used for text on disabled controls.
Return Value
The color used for text on disabled controls. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hgrayColor
Returns an NSColor object whose grayscale value is 0.5 and whose alpha value is 1.0.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hgreenColor
Returns an NSColor object whose RGB value is 0.0, 1.0, 0.0 and whose alpha value is 1.0.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hgridColor
Returns the system color used for the optional gridlines in, for example, a table view.
Return Value
The system color used for gridlines. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hheaderColor
Returns the system color used as the background color for header cells in table views and outline views.
Return Value
The system color used as the background for header cells in table and outline views. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hheaderTextColor
Returns the system color used for text in header cells in table views and outline views.
Return Value
The system color used for text in header cells in table and outline views. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hhighlightColor
Returns the system color that represents the virtual light source on the screen.
Return Value
The system color for the virtual light source on the screen.
Discussion
This method is invoked by the highlightWithLevel: method. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hignoresAlpha
Returns a Boolean value indicating whether the application supports alpha.
Return Value
YES if the application doesn't support alpha; otherwise NO. 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.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hkeyboardFocusIndicatorColor
Returns the system color that represents the keyboard focus ring around controls.
Return Value
The system color representing the focus ring.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hknobColor
Returns the system color used for the flat surface of a slider knob that hasn’t been selected.
Return Value
The system color used for an unselected slider knob.
Discussion
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 “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hlightGrayColor
Returns an NSColor object whose grayscale value is 2/3 and whose alpha value is 1.0.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hmagentaColor
Returns an NSColor object whose RGB value is 1.0, 0.0, 1.0 and whose alpha value is 1.0.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.horangeColor
Returns an NSColor object whose RGB value is 1.0, 0.5, 0.0 and whose alpha value is 1.0.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hpurpleColor
Returns an NSColor object whose RGB value is 0.5, 0.0, 0.5 and whose alpha value is 1.0.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hredColor
Returns an NSColor object whose RGB value is 1.0, 0.0, 0.0 and whose alpha value is 1.0.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hscrollBarColor
Returns the system color used for scroll “bars”—that is, for the groove in which a scroller’s knob moves
Return Value
The system color used for scroll bars. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hsecondarySelectedControlColor
Returns the system color used in non-key views.
Return Value
The system color used in non-key views. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.1 and later.
See Also
Declared In
NSColor.hselectedControlColor
Returns the system color used for the face of a selected control.
Return Value
The system color used for the face of a selected control—a control being dragged or clicked. For general information about system colors, see “Accessing System Colors”
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hselectedControlTextColor
Returns the system color used for text in a selected control—a control being clicked or dragged.
Return Value
The system color used for text in a selected control—a control being clicked or dragged. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hselectedKnobColor
Returns the system color used for the slider knob when it is selected.
Return Value
The system color used for a slider knob that is selected—that is, dragged. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hselectedMenuItemColor
Returns the system color used for the face of selected menu items.
Return Value
The system color used for selected menu items. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hselectedMenuItemTextColor
Returns the system color used for the text in menu items.
Return Value
The system color used for text in selected menu items. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hselectedTextBackgroundColor
Returns the system color used for the background of selected text.
Return Value
The system color used for the background of selected text. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hselectedTextColor
Returns the system color used for selected text.
Return Value
The system color used for selected text. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hsetIgnoresAlpha:
Specifies whether an application supports alpha.
Parameters
- flag
YESto indicate that the application won’t support alpha. By default, applications ignore alpha.
Discussion
If the application doesn't support alpha, no opacity slider is displayed in the color panel, and colors dragged in or pasted have their alpha values set to 1.0. 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. Note that calling this with a value of YES overrides any value set with the NSColorPanel method setShowsAlpha:.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hshadowColor
Returns the system color that represents the virtual shadows cast by raised objects on the screen.
Return Value
The system color for the virtual shadows case by raised objects on the screen.
Discussion
This method is invoked by shadowWithLevel:. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.htextBackgroundColor
Returns the system color used for the text background.
Return Value
The system color used for the background of text. When text is selected, its background color changes to the return value of selectedTextBackgroundColor. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.htextColor
Returns the system color used for text.
Return Value
The system color used for text. When text is selected, its color changes to the return value of selectedTextColor. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hunderPageBackgroundColor
Returns the color to use when areas revealed behind views.
Return Value
An NSColor instance.
Availability
- Available in OS X v10.8 and later.
Declared In
NSColor.hwhiteColor
Returns an NSColor object whose grayscale and alpha values are both 1.0.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hwindowBackgroundColor
Returns a pattern color that will draw the ruled lines for the window background.
Return Value
The pattern color used for the background of a window. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hwindowFrameColor
Returns the system color used for window frames, except for their text.
Return Value
The system color used for window frames. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hwindowFrameTextColor
Returns the system color used for the text in window frames.
Return Value
The system color used for text in window frames. For general information about system colors, see “Accessing System Colors”.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hyellowColor
Returns an NSColor object whose RGB value is 1.0, 1.0, 0.0 and whose alpha value is 1.0.
Return Value
The NSColor object.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hInstance Methods
alphaComponent
Returns the receiver’s alpha (opacity) component.
Return Value
The alpha component of the color object. If the receiver has no alpha component, this is 1.0 (opaque).
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hblackComponent
Returns the receiver’s black component.
Return Value
The color object's black component.
Discussion
This method works only with objects representing colors in the NSDeviceCMYKColorSpace color space. Sending it to other objects raises an exception.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hblendedColorWithFraction:ofColor:
Creates and returns an NSColor object whose component values are a weighted sum of the receiver’s and the specified color object's.
Parameters
- fraction
The amount of the color to blend with the receiver's color. 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.
- color
The color to blend with the receiver's color.
Return Value
The resulting color object or nil if the colors can’t be converted.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hblueComponent
Returns the receiver’s blue component.
Return Value
The color object's blue component.
Discussion
This method works only with objects representing colors in the NSCalibratedRGBColorSpace or NSDeviceRGBColorSpace color space. Sending it to other objects raises an exception.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hbrightnessComponent
Returns the brightness component of the HSB color equivalent to the receiver.
Return Value
The color object's brightness component.
Discussion
This method works only with objects representing colors in the NSCalibratedRGBColorSpace or NSDeviceRGBColorSpace color space. Sending it to other objects raises an exception.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hcatalogNameComponent
Returns the name of the catalog containing the receiver’s name.
Return Value
The name of the catalog containing the color object.
Discussion
This method raises an exception if the receiver’s color space isn’t NSNamedColorSpace.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hCGColor
Returns a CGColor for the color.
Return Value
A CGColor.
Discussion
This value never be NULL, although the return value may be an approximation in some cases.
There is no guaranteed round-trip color fidelity.
Availability
- Available in OS X v10.8 and later.
Declared In
NSColor.hcolorNameComponent
Returns the receiver’s name.
Return Value
The name of the color object.
Discussion
This method raises an exception if the receiver’s color space isn’t NSNamedColorSpace.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hcolorSpace
Returns an object representing the color space of the receiver.
Return Value
An object representing a color space. The returned NSColorSpace object may represent a custom color space.
Discussion
Calling this method raises an exception if the receiver is not based on a color space represented by an NSColorSpace object—specifically, colors designated by NSNamedColorSpace and NSPatternColorSpace. If you are unsure about a color object, convert it to an equivalent NSColorSpace-based object before calling this method. Color objects created with color-space names NSCalibratedWhiteColorSpace, NSCalibratedBlackColorSpace, NSCalibratedRGBColorSpace, NSDeviceWhiteColorSpace, NSDeviceBlackColorSpace, NSDeviceRGBColorSpace, NSDeviceCMYKColorSpace, or NSCustomColorSpace—or with the NSColorSpace class methods corresponding to these names—are safe to use with this method. See ““About Color Spaces”" in Color Programming Topics for a list of these corresponding methods.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSColor.hcolorSpaceName
Returns the name of the receiver’s color space.
Return Value
The name of the color space.
Discussion
This method should be implemented in subclasses of NSColor.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hcolorUsingColorSpace:
Returns a new color object representing the color of the receiver in the specified color space.
Parameters
- space
The color space of the new
NSColorobject.
Return Value
The new NSColor object. This method converts the receiver's color to an equivalent one in the new color space. Although the new color might have different component values, it looks the same as the original. Returns nil if conversion is not possible.
If the receiver's color space is the same as that specified in space, this method returns the same NSColor object.
Availability
- Available in OS X v10.4 and later.
Declared In
NSColor.hcolorUsingColorSpaceName:
Creates and returns an NSColor whose color is the same as the receiver’s, except that the new NSColor is in the specified color space.
Parameters
- colorSpace
The name of the color space containing the new
NSColorobject. If colorSpace isnil, the most appropriate color space is used.
Return Value
The new NSColor object or nil if the specified conversion cannot be done.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hcolorUsingColorSpaceName:device:
Creates and returns an NSColor object whose color is the same as the receiver’s, except that the new NSColor is in the given color space and is specific to the given device.
Parameters
- colorSpace
The name of the color space containing the new
NSColorobject. If colorSpace isnil, the most appropriate color space is used.- deviceDescription
The device description. Device descriptions can be obtained from windows, screens, and printers with the
deviceDescriptionmethod.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.
Return Value
The new NSColor object or nil if the specified conversion cannot be done.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hcolorWithAlphaComponent:
Creates and returns an NSColor object that has the same color space and component values as the receiver, but the specified alpha component.
Parameters
- alpha
The opacity value of the new
NSColorobject.
Return Value
The new NSColor object. If the receiver’s color space doesn’t include an alpha component, the receiver is returned.
Discussion
A subclass with explicit opacity components should override this method to return a color with the specified alpha.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hcyanComponent
Returns the receiver’s cyan component.
Return Value
The color object's cyan component.
Discussion
This method works only with objects representing colors in the NSDeviceCMYKColorSpace color space. Sending it to other objects raises an exception.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hdrawSwatchInRect:
Draws the current color in the given rectangle.
Parameters
- rect
The rectangle in which to draw the color.
Discussion
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.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hgetComponents:
Returns the components of the receiver as an array.
Parameters
- components
An array containing the components of the color object as
floatvalues.
Discussion
You can invoke this method on NSColor objects created from custom color spaces to get the individual floating point components, including alpha. Raises an exception if the receiver doesn’t have floating-point components. To find out how many components are in the components array, send the receiver a numberOfComponents message.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSColor.hgetCyan:magenta:yellow:black:alpha:
Returns the receiver’s CMYK and opacity values.
Parameters
- cyan
Upon return, contains the cyan component of the color object.
- magenta
Upon return, contains the magenta component of the color object.
- yellow
Upon return, contains the yellow component of the color object.
- black
Upon return, contains the black component of the color object.
- alpha
Upon return, contains opacity value of the color object.
Discussion
If NULL is passed in as an argument, the method doesn’t set that value. This method works only with objects representing colors in the NSDeviceCMYKColorSpace. Sending it to other objects raises an exception.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hgetHue:saturation:brightness:alpha:
Returns the receiver’s HSB component and opacity values in the respective arguments.
Parameters
- hue
Upon return, contains the hue component of the color object.
- saturation
Upon return, contains the saturation component of the color object.
- brightness
Upon return, contains the brightness component of the color object.
- alpha
Upon return, contains the opacity value of the color object.
Discussion
If NULL is passed in as an argument, the method doesn’t set that value. This method works only with objects representing colors in the NSCalibratedRGBColorSpace or NSDeviceRGBColorSpace color space. Sending it to other objects raises an exception.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hgetRed:green:blue:alpha:
Returns the receiver’s RGB component and opacity values in the respective arguments.
Parameters
- red
Upon return, contains the red component of the color object.
- green
Upon return, contains the green component of the color object.
- blue
Upon return, contains the blue component of the color object.
- alpha
Upon return, contains the opacity value of the color object.
Discussion
If NULL is passed in as an argument, the method doesn’t set that value. This method works only with objects representing colors in the NSCalibratedRGBColorSpace or NSDeviceRGBColorSpace color space. Sending it to other objects raises an exception.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hgetWhite:alpha:
Returns the receiver’s grayscale value and alpha values.
Parameters
- white
Upon return, contains the grayscale value of the color object.
- alpha
Upon return, contains the opacity value of the color object.
Discussion
If NULL is passed in as an argument, the method doesn’t set that value. This method works only with objects representing colors in the NSCalibratedWhiteColorSpace, NSCalibratedBlackColorSpace, NSDeviceBlackColorSpace, or NSDeviceWhiteColorSpace color space. Sending it to other objects raises an exception.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hgreenComponent
Returns the receiver’s green component.
Return Value
The color object's green component.
Discussion
This method works only with objects representing colors in the NSCalibratedRGBColorSpace or NSDeviceRGBColorSpace color space. Sending it to other objects raises an exception.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hhighlightWithLevel:
Returns an NSColor object that represents a blend between the receiver and the highlight color returned by highlightColor.
Parameters
- highlightLevel
The amount of the highlight color that is blended with the receiver's color. This should be a number from 0.0 through 1.0. A highlightLevel below 0.0 is interpreted as 0.0; a highlightLevel above 1.0 is interpreted as 1.0.
Return Value
The new NSColor object. Returns nil if the colors can’t be converted.
Discussion
Invoke this method when you want to brighten the receiving NSColor for use in highlights.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hhueComponent
Returns the hue component of the HSB color equivalent to the receiver.
Return Value
The color object's hue component.
Discussion
This method works only with objects representing colors in the NSCalibratedRGBColorSpace or NSDeviceRGBColorSpace color space. Sending it to other objects raises an exception.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hlocalizedCatalogNameComponent
Returns the name of the catalog containing the receiver's name as a localized string.
Return Value
The name of catalog containing the color object's name as a localized string. This string may be displayed in user interface items like color pickers.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hlocalizedColorNameComponent
Returns the name of the receiver as a localized string.
Return Value
The name of color object as a localized string. This string may be displayed in user interface items like color pickers.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hmagentaComponent
Returns the receiver’s magenta component.
Return Value
The color object's magenta component.
Discussion
This method works only with objects representing colors in the NSDeviceCMYKColorSpace color space. Sending it to other objects raises an exception.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hnumberOfComponents
Returns the number of components in the receiver.
Return Value
The number of components in the color object. The floating-point components counted include alpha. This method raises an exception if the receiver doesn’t have floating-point components.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSColor.hpatternImage
Returns the image that the receiver is using as a pattern.
Return Value
The image used by the color object. If the receiver doesn’t have an image, this method raises an exception.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hredComponent
Returns the receiver’s red component.
Return Value
The color object's red component.
Discussion
This method works only with objects representing colors in the NSCalibratedRGBColorSpace or NSDeviceRGBColorSpace color space. Sending it to other objects raises an exception.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hsaturationComponent
Returns the saturation component of the HSB color equivalent to the receiver.
Return Value
The color object's saturation component.
Discussion
This method works only with objects representing colors in the NSCalibratedRGBColorSpace or NSDeviceRGBColorSpace color space. Sending it to other objects raises an exception.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hset
Sets the color of subsequent drawing to the color that the receiver represents.
Discussion
This method should be implemented in subclasses.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hsetFill
Sets the fill color of subsequent drawing to the receiver’s color.
Discussion
This method should be implemented in subclasses.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSColor.hsetStroke
Sets the stroke color of subsequent drawing to the receiver’s color.
Discussion
This method should be implemented in subclasses.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSColor.hshadowWithLevel:
Returns an NSColor object that represents a blend between the receiver and the shadow color returned by shadowColor.
Parameters
- shadowLevel
The amount of the shadow color used for the blend. This should be a number from 0.0 through 1.0. A shadowLevel below 0.0 is interpreted as 0.0; a shadowLevel above 1.0 is interpreted as 1.0.
Return Value
The new NSColor object. Returns nil if the colors can’t be converted.
Discussion
Invoke this method when you want to darken the receiving NSColor for use in shadows.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hwhiteComponent
Returns the receiver’s white component.
Return Value
The color object's white component.
Discussion
This method works only with objects representing colors in the NSCalibratedWhiteColorSpace, NSCalibratedBlackColorSpace, NSDeviceBlackColorSpace, or NSDeviceWhiteColorSpace color space. Sending it to other objects raises an exception.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hwriteToPasteboard:
Writes the receiver’s data to the specified pasteboard.
Parameters
- pasteBoard
The pasteboard to which to write the receiver's color data. If this pasteboard doesn’t support color data, the method does nothing.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSColor.hyellowComponent
Returns the receiver’s yellow component.
Return Value
The color object's yellow component.
Discussion
This method works only with objects representing colors in the NSDeviceCMYKColorSpace color space. Sending it to other objects raises an exception.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.hConstants
For definitions of NSColor constants, as well as a discussion of their usage, see ““About Color Spaces”” in Color Programming Topics.
AppKit Versions for NSColor Bug Fixes
The version of the AppKit framework containing a specific bug fix.
#define NSAppKitVersionNumberWithPatternColorLeakFix 641.0
Constants
NSAppKitVersionNumberWithPatternColorLeakFixThe specific version of the AppKit framework that introduced the fix for correctly autoreleasing objects returned by the
colorWithPatternImage:method. Developers should not need to use this constant unless they are writing applications for OS X v10.1 and earlier.Available in OS X v10.2 and later.
Declared in
NSColor.h.
Notifications
NSSystemColorsDidChangeNotification
This notification contains no notification object and no userInfo dictionary.
Availability
- Available in OS X v10.0 and later.
Declared In
NSColor.h© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-07-23)