Adding your own colors to core-plot


In HTML colors are typically specified in a HEX format, where each color is a number from 0 to 255 represented as a two digit hex number. For example, the aqua blue shade color is represented as 0095D2, where the value for Red is 00, the value for Green is 95 and the value of Blue is D2. For iPhone development, the colors are specified in RGB float where each of the RGB colors is a number between 0.0 to 1.0.

In core-plot, you can add your own colors via Objective-C category construct from within any of your own header and implementation files.

@interface CPColor (AQ_COLOR)
 +(CPColor *)aq_blue_color; // #0095D2 
@end
@implementation CPColor (AQ_COLOR)

+(CPColor *) aq_blue_color { 
    static CPColor *color = nil;
    if ( nil == color ) {
		color = [[CPColor alloc] initWithComponentRed:(0x00&0xff)/255.0 green:(0x95&0xFF)/255.0 blue:(0xD2&0xFF)/255.0 alpha:1.0];
    }
	return color; 
}
@end

Now you can use this color to fill a bar chart, e.g.

barPlot.fill = [CPFill fillWithColor:[CPColor aq_blue_color]];

2 Responses to “Adding your own colors to core-plot”

  1. ksiegowosc wroclaw Says:

    Very nice information, thanks a lot.

  2. learn Says:

    learn…

    […]Adding your own colors to core-plot « n o t e 1 9 . c o m[…]…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: