O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required