Tag Archives: Core Graphics

CGColorCreateGenericRGB Error on iPhone SDK 3.0

While porting some Core Graphics/Quartz 2D code from the Mac to the iPhone, I ran across the following error:

error: 'CGColorCreateGenericRGB' is unavailable (declared at

/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGColor.h:31)

Looking in the header file in question (CGColor.h), I found the following:

/* Create a color in the "Generic" RGB color space. */

CG_EXTERN CGColorRef CGColorCreateGenericRGB(CGFloat red, CGFloat green,
    CGFloat blue, CGFloat alpha)
    CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_NA);

So the header file pretty much confirms what the error says; the function is not available on the iPhone.

After a little bit of looking through documentation, you just have to specify the color space manually and then give the components to the color. So the this:

CGColorCreateGenericRGB(0.90625, 0.80, 0.80, 1.0)

would become


CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
const CGFloat myColor[] = {0.90625, 0.80, 0.80, 1.0};
CGColorCreate(rgb, myColor);
CGColorSpaceRelease(rgb);

Cocoa LCD Screen View

As part of an iPhone application I’m developing, I need a view that will display numbers/times in a way that will look like an old liquid crystal display calculator. I looked around at using various fonts to cover the same effect, but I wanted the look where you could slightly see the non-lit components of the display. As such, I delved into the mystical world of Quartz 2D.

Example of the LCD view showing the current time.

Example of the LCD view showing the current time.

MTILcdView allows you to set three parameters: the color for the “lit” crystals, the color for the “dim” crystals, and the text to be displayed. The view currently only supports displaying numbers plus the colon (“:”) per my needs, but it could easily be extended to display letters as well. The view decides the size of the digits to be displayed based on the height of the view, so for a given height you must adjust the width of the view to allow the needed number of characters to be displayed.

The source code for the Mac is available here: MTILcdView.h, MTILcdView.m. A complete demo application using the view can be retrieved from GitHub here.

MTILcdView running on iPhone

MTILcdView running on iPhone

The source code for the iPhone 3.0 SDK is available here: MTILcdView.h, MTILcdView.m (note that you must manually rename the files from MTILcdView1.{h|m} to MTILcdView.{h|m}). A complete demo application using the view can be retrieved from GitHub here.