Class CPColor

CPObject
    extended byCPColor

@implementation CPColor : CPObject

CPColor can be used to represent color in an RGB or HSB model with an optional transparency value.

It also provides some class helper methods that returns instances of commonly used colors.

The class does not have a set: method like NextStep based frameworks to change the color of the current context. To change the color of the current context, use CGContextSetFillColor().


Method Summary
+(CPColor)blackColor
          Returns a black color object.
+(CPColor)blueColor
          Returns a blue color object.
+(CPColor)colorWithCSSString:(CPString)aString
          Creates a CPColor from a valid CSS RGB string.
+(CPColor)colorWithCalibratedRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha
          Creates a color in the RGB color space, with an alpha value.
+(CPColor)colorWithCalibratedWhite:(float)white alpha:(float)alpha
          Creates a new color object with white for the RGB components.
+(CPColor)colorWithHexString:(string)hex
          Creates an RGB color from a hexadecimal string.
+(CPColor)colorWithHue:(float)hue saturation:(float)saturation brightness:(float)brightness
          Creates a new color in HSB space.
+(CPColor)colorWithPatternImage:(CPImage)anImage
          Creates a color using a tile pattern with anImage.
+(CPColor)darkGrayColor
          Returns a dark gray color object.
+(CPColor)grayColor
          Returns a gray color object.
+(CPColor)greenColor
          Returns a green color object.
+(CPColor)lightGrayColor
          Returns a light gray color object (RGBA=[0.
+(CPColor)redColor
          Returns a red color object (RGBA=[1.
+(CPColor)shadowColor
          Returns a shadow looking color (RGBA=[0.
+(CPColor)whiteColor
          Returns a white color object (RGBA=[1.
+(CPColor)yellowColor
          Returns a yellow color object (RGBA=[1.
-(id)initWithCoder:(CPCoder)aCoder
          Initializes this color from the data archived in a coder.
-(float)alphaComponent
          Returns the alpha component of this color.
-(float)blueComponent
          Returns the blue component of this color.
-(CPColor)colorWithAlphaComponent:(float)anAlphaComponent
          Returns a new color with the same RGB as the receiver but a new alpha component.
-(CPArray)components
          Returns the RGBA components of this color in an array.
-(CPString)cssString
          Returns the CSS representation of this color.
-(void)encodeWithCoder:(CPCoder)aCoder
          Archives this color into a coder.
-(float)greenComponent
          Returns the green component of this color.
-(CPString)hexString
          Returns a 6 character long hex string of this color.
-(CPArray)hsbComponents
          Returns an array with the HSB values for this color.
-(CPImage)patternImage
          Returns the image being used as the pattern for the tile in this color.
-(float)redComponent
          Return the red component of this color.

Methods inherited from class CPObject
initialize, alloc, class, instanceMethodForSelector, instancesRespondToSelector, isSubclassOfClass, load, new, setVersion, superclass, version, init, autorelease, awakeAfterUsingCoder, class, classForCoder, classForKeyedArchiver, className, copy, dealloc, description, doesNotRecognizeSelector, forwardInvocation, hash, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableCopy, performSelector, performSelector, performSelector, release, replacementObjectForArchiver, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, retain, self, superclass


Method Detail

blackColor

+(CPColor)blackColor
Returns a black color object. (RGBA=[0.0, 0.0, 0.0, 1.0])

blueColor

+(CPColor)blueColor
Returns a blue color object. (RGBA=[0.0, 0.0, 1.0, 1.0])

colorWithCSSString

+(CPColor)colorWithCSSString:(CPString)aString
Creates a CPColor from a valid CSS RGB string. Example, "rgb(32,64,129)".
Parameters:
aString - a CSS color string
Returns:
a color initialized to the value in the css string

colorWithCalibratedRed

+(CPColor)colorWithCalibratedRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha
Creates a color in the RGB color space, with an alpha value. Each component should be between the range of 0.0 to 1.0. For the alpha component, a value of 1.0 is opaque, and 0.0 means completely transparent.
Parameters:
red - the red component of the color
green - the green component of the color
blue - the blue component of the color
alpha - the alpha component
Returns:
a color initialized to the values specified

colorWithCalibratedWhite

+(CPColor)colorWithCalibratedWhite:(float)white alpha:(float)alpha
Creates a new color object with white for the RGB components. For the alpha component, a value of 1.0 is opaque, and 0.0 means completely transparent.
Parameters:
white - a float between 0.0 and 1.0
alpha - the alpha component between 0.0 and 1.0
Returns:
a color initialized to the values specified

colorWithHexString

+(CPColor)colorWithHexString:(string)hex
Creates an RGB color from a hexadecimal string. For example, the a string of "FFFFFF" would return a white CPColor. "FF0000" would return a pure red, "00FF00" would return a pure blue, and "0000FF" would return a pure green.
Parameters:
hex - a 6 character long string of hex
Returns:
an initialized RGB color

colorWithHue

+(CPColor)colorWithHue:(float)hue saturation:(float)saturation brightness:(float)brightness
Creates a new color in HSB space.
Parameters:
hue - the hue value
saturation - the saturation value
brightness - the brightness value
Returns:
the initialized color

colorWithPatternImage

+(CPColor)colorWithPatternImage:(CPImage)anImage
Creates a color using a tile pattern with anImage
Parameters:
anImage
Returns:
a tiled image color object

darkGrayColor

+(CPColor)darkGrayColor
Returns a dark gray color object. (RGBA=[0.33 ,0.33, 0.33, 1.0])

grayColor

+(CPColor)grayColor
Returns a gray color object. (RGBA=[0.5, 0.5, 0.5, 1.0])

greenColor

+(CPColor)greenColor
Returns a green color object. (RGBA=[0.0, 1.0, 0.0, 1.0])

lightGrayColor

+(CPColor)lightGrayColor
Returns a light gray color object (RGBA=[0.66, 0.66, 0.66, 1.0])

redColor

+(CPColor)redColor
Returns a red color object (RGBA=[1.0, 0.0, 0.0, 1.0])

shadowColor

+(CPColor)shadowColor
Returns a shadow looking color (RGBA=[0.0, 0.0, 0.0, 0.33])

whiteColor

+(CPColor)whiteColor
Returns a white color object (RGBA=[1.0, 1.0, 1.0, 1.0])

yellowColor

+(CPColor)yellowColor
Returns a yellow color object (RGBA=[1.0, 1.0, 0.0, 1.0])

initWithCoder

-(id)initWithCoder:(CPCoder)aCoder
Initializes this color from the data archived in a coder.
Parameters:
aCoder - the coder from which the color will be loaded

alphaComponent

-(float)alphaComponent
Returns the alpha component of this color.

blueComponent

-(float)blueComponent
Returns the blue component of this color.

colorWithAlphaComponent

-(CPColor)colorWithAlphaComponent:(float)anAlphaComponent
Returns a new color with the same RGB as the receiver but a new alpha component.
Parameters:
anAlphaComponent - the alpha component for the new color
Returns:
a new color object

components

-(CPArray)components
Returns the RGBA components of this color in an array. The index values are ordered as:
Index   Component
0       Red
1       Green
2       Blue
3       Alpha

cssString

-(CPString)cssString
Returns the CSS representation of this color. The color will be in one of the following forms:
rgb(22,44,88)
rgba(22,44,88,0.5)  // if there is an alpha
url("data:image/png;base64,BASE64ENCODEDDATA")  // if there is a pattern image

encodeWithCoder

-(void)encodeWithCoder:(CPCoder)aCoder
Archives this color into a coder.
Parameters:
aCoder - the coder into which the color will be archived.

greenComponent

-(float)greenComponent
Returns the green component of this color.

hexString

-(CPString)hexString
Returns a 6 character long hex string of this color.

hsbComponents

-(CPArray)hsbComponents
Returns an array with the HSB values for this color. The index values are ordered as:
Index   Component
0       Hue
1       Saturation
2       Brightness

patternImage

-(CPImage)patternImage
Returns the image being used as the pattern for the tile in this color.

redComponent

-(float)redComponent
Return the red component of this color.

Created on Sat Sep 13 14:15:43 PDT 2008