Mac Developer Library

Developer

AppKit Framework Reference NSColor Class Reference

Options
Deployment Target:

On This Page
Language:

NSColor

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.

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

Inheritance


Import Statement


import AppKit @import AppKit;

Availability


Available in OS X v10.0 and later.
  • Creates and returns an NSColor object using the given opacity and HSB color space components.

    Declaration

    Swift

    init(calibratedHue hue: CGFloat, saturation saturation: CGFloat, brightness brightness: CGFloat, alpha alpha: CGFloat) -> NSColor

    Objective-C

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

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates and returns an NSColor object using the given opacity and RGB components.

    Declaration

    Swift

    init(calibratedRed red: CGFloat, green green: CGFloat, blue blue: CGFloat, alpha alpha: CGFloat) -> NSColor

    Objective-C

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

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates and returns an NSColor object using the given opacity and grayscale value.

    Declaration

    Swift

    init(calibratedWhite white: CGFloat, alpha alpha: CGFloat) -> NSColor

    Objective-C

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

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates and returns an NSColor object by finding the color with the specified name in the given catalog.

    Declaration

    Swift

    init?(catalogName listName: String, colorName colorName: String) -> NSColor

    Objective-C

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

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates and returns an NSColor object using the given opacity value and CMYK components.

    Declaration

    Swift

    init(deviceCyan cyan: CGFloat, magenta magenta: CGFloat, yellow yellow: CGFloat, black black: CGFloat, alpha alpha: CGFloat) -> NSColor

    Objective-C

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

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates and returns an NSColor object using the given opacity value and HSB color space components.

    Declaration

    Swift

    init(deviceHue hue: CGFloat, saturation saturation: CGFloat, brightness brightness: CGFloat, alpha alpha: CGFloat) -> NSColor

    Objective-C

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

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates and returns an NSColor object using the given opacity value and RGB components.

    Declaration

    Swift

    init(deviceRed red: CGFloat, green green: CGFloat, blue blue: CGFloat, alpha alpha: CGFloat) -> NSColor

    Objective-C

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

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates and returns an NSColor object using the given opacity and grayscale values.

    Declaration

    Swift

    init(deviceWhite white: CGFloat, alpha alpha: CGFloat) -> NSColor

    Objective-C

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

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Converts a Core Image color object to its NSColor equivalent.

    Declaration

    Swift

    init(CIColor color: CIColor) -> NSColor

    Objective-C

    + (NSColor *)colorWithCIColor:(CIColor *)color

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns an NSColor object created from the specified components of the given color space.

    Declaration

    Swift

    init(colorSpace space: NSColorSpace, components components: UnsafePointer<CGFloat>, count numberOfComponents: Int) -> NSColor

    Objective-C

    + (NSColor *)colorWithColorSpace:(NSColorSpace *)space components:(const CGFloat *)components count:(NSInteger)numberOfComponents

    Parameters

    space

    An NSColorSpace object representing a color space. The method raises if this is nil.

    components

    An array of the components in the specified color space to use to create the NSColor object. 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 components array. 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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns a color created from the specified components in the sRGB colorspace.

    Declaration

    Swift

    init(SRGBRed red: CGFloat, green green: CGFloat, blue blue: CGFloat, alpha alpha: CGFloat) -> NSColor

    Objective-C

    + (NSColor *)colorWithSRGBRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Returns an color created with the specified white and alpha values in the GenericGamma22 colorspace.

    Declaration

    Swift

    init(genericGamma22White white: CGFloat, alpha alpha: CGFloat) -> NSColor

    Objective-C

    + (NSColor *)colorWithGenericGamma22White:(CGFloat)white alpha:(CGFloat)alpha

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Creates and returns an NSColor object with the specified hue, saturation, brightness, and alpha channel values.

    Declaration

    Swift

    init(hue hue: CGFloat, saturation saturation: CGFloat, brightness brightness: CGFloat, alpha alpha: CGFloat) -> NSColor

    Objective-C

    + (NSColor *)colorWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha

    Parameters

    hue

    The hue (color) component, expressed as a floating-point value in the range 0–1.0.

    saturation

    The color saturation component, expressed as a floating-point value in the range 0–1.0.

    brightness

    The brightness component, expressed as a floating-point value in the range 0–1.0.

    alpha

    The alpha (opacity), expressed as a floating-point value in the range 0 (transparent) to 1.0 (opaque).

    Discussion

    This method creates an NSCustomColorSpace color that is compatible with the sRGB colorspace. This method is provided for easier reuse of code that uses UIColor on iOS.

    Where possible, it is preferable to specify the colorspace explicitly using the colorWithSRGBRed:green:blue:alpha: or colorWithGenericGamma22White:alpha: method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.9 and later.

  • Creates and returns an NSColor object with the specified red, green, blue, and alpha channel values.

    Declaration

    Swift

    init(red red: CGFloat, green green: CGFloat, blue blue: CGFloat, alpha alpha: CGFloat) -> NSColor

    Objective-C

    + (NSColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha

    Parameters

    red

    The red channel value, expressed as a floating-point value in the range 0–1.0.

    green

    The green channel value, expressed as a floating-point value in the range 0–1.0.

    blue

    The blue channel value, expressed as a floating-point value in the range 0–1.0.

    alpha

    The alpha (opacity), expressed as a floating-point value in the range 0 (transparent) to 1.0 (opaque).

    Discussion

    This method creates an NSCustomColorSpace color that is compatible with the sRGB colorspace. This method is provided for easier reuse of code that uses UIColor on iOS.

    Where possible, it is preferable to specify the colorspace explicitly using the colorWithSRGBRed:green:blue:alpha: or colorWithGenericGamma22White:alpha: method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.9 and later.

  • Creates and returns a white (or grey) NSColor object with the specified brightness and alpha channel values.

    Declaration

    Swift

    init(white white: CGFloat, alpha alpha: CGFloat) -> NSColor

    Objective-C

    + (NSColor *)colorWithWhite:(CGFloat)white alpha:(CGFloat)alpha

    Parameters

    white

    The brightness, expressed as a floating-point value in the range 0–1.0.

    alpha

    The alpha (opacity), expressed as a floating-point value in the range 0 (transparent) to 1.0 (opaque).

    Discussion

    This method creates an NSCustomColorSpace color that is compatible with the sRGB colorspace. This method is provided for easier reuse of code that uses UIColor on iOS.

    Where possible, it is preferable to specify the colorspace explicitly using the colorWithSRGBRed:green:blue:alpha: or colorWithGenericGamma22White:alpha: method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.9 and later.

  • Returns an NSColor object whose grayscale value is 0.0 and whose alpha value is 1.0.

    Declaration

    Swift

    class func blackColor() -> NSColor

    Objective-C

    + (NSColor *)blackColor

    Return Value

    The NSColor object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object whose RGB value is 0.0, 0.0, 1.0 and whose alpha value is 1.0.

    Declaration

    Swift

    class func blueColor() -> NSColor

    Objective-C

    + (NSColor *)blueColor

    Return Value

    The NSColor object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object whose RGB value is 0.6, 0.4, 0.2 and whose alpha value is 1.0.

    Declaration

    Swift

    class func brownColor() -> NSColor

    Objective-C

    + (NSColor *)brownColor

    Return Value

    The NSColor object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object whose grayscale and alpha values are both 0.0.

    Declaration

    Swift

    class func clearColor() -> NSColor

    Objective-C

    + (NSColor *)clearColor

    Return Value

    The NSColor object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object whose RGB value is 0.0, 1.0, 1.0 and whose alpha value is 1.0.

    Declaration

    Swift

    class func cyanColor() -> NSColor

    Objective-C

    + (NSColor *)cyanColor

    Return Value

    The NSColor object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object whose grayscale value is 1/3 and whose alpha value is 1.0.

    Declaration

    Swift

    class func darkGrayColor() -> NSColor

    Objective-C

    + (NSColor *)darkGrayColor

    Return Value

    The NSColor object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object whose grayscale value is 0.5 and whose alpha value is 1.0.

    Declaration

    Swift

    class func grayColor() -> NSColor

    Objective-C

    + (NSColor *)grayColor

    Return Value

    The NSColor object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object whose RGB value is 0.0, 1.0, 0.0 and whose alpha value is 1.0.

    Declaration

    Swift

    class func greenColor() -> NSColor

    Objective-C

    + (NSColor *)greenColor

    Return Value

    The NSColor object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object whose grayscale value is 2/3 and whose alpha value is 1.0.

    Declaration

    Swift

    class func lightGrayColor() -> NSColor

    Objective-C

    + (NSColor *)lightGrayColor

    Return Value

    The NSColor object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object whose RGB value is 1.0, 0.0, 1.0 and whose alpha value is 1.0.

    Declaration

    Swift

    class func magentaColor() -> NSColor

    Objective-C

    + (NSColor *)magentaColor

    Return Value

    The NSColor object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object whose RGB value is 1.0, 0.5, 0.0 and whose alpha value is 1.0.

    Declaration

    Swift

    class func orangeColor() -> NSColor

    Objective-C

    + (NSColor *)orangeColor

    Return Value

    The NSColor object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object whose RGB value is 0.5, 0.0, 0.5 and whose alpha value is 1.0.

    Declaration

    Swift

    class func purpleColor() -> NSColor

    Objective-C

    + (NSColor *)purpleColor

    Return Value

    The NSColor object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object whose RGB value is 1.0, 0.0, 0.0 and whose alpha value is 1.0.

    Declaration

    Swift

    class func redColor() -> NSColor

    Objective-C

    + (NSColor *)redColor

    Return Value

    The NSColor object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object whose grayscale and alpha values are both 1.0.

    Declaration

    Swift

    class func whiteColor() -> NSColor

    Objective-C

    + (NSColor *)whiteColor

    Return Value

    The NSColor object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object whose RGB value is 1.0, 1.0, 0.0 and whose alpha value is 1.0.

    Declaration

    Swift

    class func yellowColor() -> NSColor

    Objective-C

    + (NSColor *)yellowColor

    Return Value

    The NSColor object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates and returns an NSColor object that uses the specified image pattern.

    Declaration

    Swift

    init(patternImage image: NSImage) -> NSColor

    Objective-C

    + (NSColor *)colorWithPatternImage:(NSImage *)image

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the image that the receiver is using as a pattern.

    Declaration

    Swift

    var patternImage: NSImage { get }

    Objective-C

    @property(readonly, strong) NSImage *patternImage

    Return Value

    The image used by the color object. If the receiver doesn’t have an image, this method raises an exception.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value indicating whether the application supports alpha.

    Declaration

    Swift

    class func ignoresAlpha() -> Bool

    Objective-C

    + (BOOL)ignoresAlpha

    Return Value

    YEStrue if the application doesn't support alpha; otherwise NOfalse. 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 YEStrue 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 NOfalse.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Specifies whether an application supports alpha.

    Declaration

    Swift

    class func setIgnoresAlpha(_ flag: Bool)

    Objective-C

    + (void)setIgnoresAlpha:(BOOL)flag

    Parameters

    flag

    YEStrue to 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 NOfalse and explicitly make colors opaque in cases where it matters to them. Note that calling this with a value of YEStrue overrides any value set with the NSColorPanel method setShowsAlpha:.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the NSColor currently on the given pasteboard.

    Declaration

    Swift

    init?(fromPasteboard pasteBoard: NSPasteboard) -> NSColor

    Objective-C

    + (NSColor *)colorFromPasteboard:(NSPasteboard *)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 YEStrue.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Writes the receiver’s data to the specified pasteboard.

    Declaration

    Swift

    func writeToPasteboard(_ pasteBoard: NSPasteboard)

    Objective-C

    - (void)writeToPasteboard:(NSPasteboard *)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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s CMYK and opacity values.

    Declaration

    Swift

    func getCyan(_ cyan: UnsafeMutablePointer<CGFloat>, magenta magenta: UnsafeMutablePointer<CGFloat>, yellow yellow: UnsafeMutablePointer<CGFloat>, black black: UnsafeMutablePointer<CGFloat>, alpha alpha: UnsafeMutablePointer<CGFloat>)

    Objective-C

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

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s HSB component and opacity values in the respective arguments.

    Declaration

    Swift

    func getHue(_ hue: UnsafeMutablePointer<CGFloat>, saturation saturation: UnsafeMutablePointer<CGFloat>, brightness brightness: UnsafeMutablePointer<CGFloat>, alpha alpha: UnsafeMutablePointer<CGFloat>)

    Objective-C

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

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s RGB component and opacity values in the respective arguments.

    Declaration

    Swift

    func getRed(_ red: UnsafeMutablePointer<CGFloat>, green green: UnsafeMutablePointer<CGFloat>, blue blue: UnsafeMutablePointer<CGFloat>, alpha alpha: UnsafeMutablePointer<CGFloat>)

    Objective-C

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

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s grayscale value and alpha values.

    Declaration

    Swift

    func getWhite(_ white: UnsafeMutablePointer<CGFloat>, alpha alpha: UnsafeMutablePointer<CGFloat>)

    Objective-C

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

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the components of the receiver as an array.

    Declaration

    Swift

    func getComponents(_ components: UnsafeMutablePointer<CGFloat>)

    Objective-C

    - (void)getComponents:(CGFloat *)components

    Parameters

    components

    An array containing the components of the color object as float values.

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    See Also

    – colorSpace

  • Returns the number of components in the receiver.

    Declaration

    Swift

    var numberOfComponents: Int { get }

    Objective-C

    @property(readonly) NSInteger numberOfComponents

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns the name of the receiver’s color space.

    Declaration

    Swift

    var colorSpaceName: String { get }

    Objective-C

    @property(readonly, copy) NSString *colorSpaceName

    Return Value

    The name of the color space.

    Discussion

    This method should be implemented in subclasses of NSColor.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func colorUsingColorSpaceName(_ colorSpace: String) -> NSColor?

    Objective-C

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

    Parameters

    colorSpace

    The name of the color space containing the new NSColor object. If colorSpace is nil, the most appropriate color space is used.

    Return Value

    The new NSColor object or nil if the specified conversion cannot be done.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func colorUsingColorSpaceName(_ colorSpace: String?, device deviceDescription: [NSObject : AnyObject]?) -> NSColor?

    Objective-C

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

    Parameters

    colorSpace

    The name of the color space containing the new NSColor object. If colorSpace is nil, the most appropriate color space is used.

    deviceDescription

    The device description. Device descriptions can be obtained from windows, screens, and printers with the deviceDescription method.

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an object representing the color space of the receiver.

    Declaration

    Swift

    var colorSpace: NSColorSpace { get }

    Objective-C

    @property(readonly, strong) NSColorSpace *colorSpace

    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" in Color Programming Topics for a list of these corresponding methods.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns a new color object representing the color of the receiver in the specified color space.

    Declaration

    Swift

    func colorUsingColorSpace(_ space: NSColorSpace) -> NSColor?

    Objective-C

    - (NSColor *)colorUsingColorSpace:(NSColorSpace *)space

    Parameters

    space

    The color space of the new NSColor object.

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Creates and returns an NSColor object whose component values are a weighted sum of the receiver’s and the specified color object's.

    Declaration

    Swift

    func blendedColorWithFraction(_ fraction: CGFloat, ofColor color: NSColor) -> NSColor?

    Objective-C

    - (NSColor *)blendedColorWithFraction:(CGFloat)fraction ofColor:(NSColor *)color

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates and returns an NSColor object that has the same color space and component values as the receiver, but the specified alpha component.

    Declaration

    Swift

    func colorWithAlphaComponent(_ alpha: CGFloat) -> NSColor

    Objective-C

    - (NSColor *)colorWithAlphaComponent:(CGFloat)alpha

    Parameters

    alpha

    The opacity value of the new NSColor object.

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object that represents a blend between the receiver and the highlight color returned by highlightColor.

    Declaration

    Swift

    func highlightWithLevel(_ highlightLevel: CGFloat) -> NSColor?

    Objective-C

    - (NSColor *)highlightWithLevel:(CGFloat)highlightLevel

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSColor object that represents a blend between the receiver and the shadow color returned by shadowColor.

    Declaration

    Swift

    func shadowWithLevel(_ shadowLevel: CGFloat) -> NSColor?

    Objective-C

    - (NSColor *)shadowWithLevel:(CGFloat)shadowLevel

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns a CGColor for the color.

    Declaration

    Swift

    var CGColor: CGColor { get }

    Objective-C

    @property(readonly) CGColorRef CGColor

    Return Value

    A CGColor.

    Discussion

    This method never returns NULL, although the return value may be an approximation in some cases.

    There is no guaranteed round-trip color fidelity.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.8 and later.

  • Creates and returns a new color using the specified CGColor.

    Declaration

    Swift

    init!(CGColor cgColor: CGColor) -> NSColor

    Objective-C

    + (NSColor *)colorWithCGColor:(CGColorRef)cgColor

    Parameters

    cgColor

    The CGColor.

    Return Value

    An NSColor instance.

    Discussion

    This method may return nil.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.8 and later.

  • Draws the current color in the given rectangle.

    Declaration

    Swift

    func drawSwatchInRect(_ rect: NSRect)

    Objective-C

    - (void)drawSwatchInRect:(NSRect)rect

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the color of subsequent drawing to the color that the receiver represents.

    Declaration

    Swift

    func set()

    Objective-C

    - (void)set

    Discussion

    This method should be implemented in subclasses.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the fill color of subsequent drawing to the receiver’s color.

    Declaration

    Swift

    func setFill()

    Objective-C

    - (void)setFill

    Discussion

    This method should be implemented in subclasses.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    See Also

    – setStroke

  • Sets the stroke color of subsequent drawing to the receiver’s color.

    Declaration

    Swift

    func setStroke()

    Objective-C

    - (void)setStroke

    Discussion

    This method should be implemented in subclasses.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    See Also

    – setFill

  • The version of the AppKit framework containing a specific bug fix.

    Declaration

    Swift

    var NSAppKitVersionNumberWithPatternColorLeakFix: Double { get }

    Objective-C

    #define NSAppKitVersionNumberWithPatternColorLeakFix 641.0

    Constants

    • NSAppKitVersionNumberWithPatternColorLeakFix

      NSAppKitVersionNumberWithPatternColorLeakFix

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

    Import Statement