Name

NSColor — Mac OS X 10.0

Synopsis

This class represents a color in the Application Kit. Each color has a colorspace associated with it, and the color components that are recognized by that color space. NSColor supports six color spaces identified by the following constants:

  • NSDeviceCMYKColorSpace

  • NSDeviceWhiteColorSpace

  • NSDeviceRGBColor

  • NSCalibratedWhiteColorSpace

  • NSCalibratedRGBColorSpace

  • NSNamedColorSpace

Calibrated colorspaces use Apple’s ColorSync technology to ensure that colors look the same on all output devices. Device colorspaces, on the other hand, do not employ ColorSync calibration, and the appearance of colors is thus device-dependent.

The set method is one of the most commonly used methods of NSColor, as it sets the color that all subsequent drawing operations should use. NSColor declares a number of methods for determining the values of various color components, converting colors between colorspaces, creating NSColor objects by changing components of an existing color object, and more. Additionally, there are a number of convenience contructors such as blueColor, redColor, and blackColor that return premade colors without having to specify component values.

image with no caption

@interface NSColor : NSObject <NSCoding, NSCopying>
                                  // Convenience Constructors
   + (NSColor *)colorForControlTint:(NSControlTint)controlTint;
   + (NSColor *)colorFromPasteboard:(NSPasteboard *)pasteBoard ...

Get Cocoa in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.