Tag Archives: Quartz 2D

Cocoa/UIKit BulbView

In my continuing saga to bring old-school displays to new-school (word?) devices, I’ve created a “bulb view” that displays characters in a grid of “lights”. The best way to describe it is probably just to see it:

BulbView from Mac

BulbView from Mac

BulbView on iPhone

BulbView on iPhone

Like previous LCD view you can set the colors for the lit & dim bulbs, but improved from the LCD view, you can use letters, numbers, and most punctuation/special characters. Again the rendering is done in pure Quartz2D.

The source, including demo apps for both the Mac and iPhone, can be found here. With this view I was smart and made it conditionally compile various parts so that it can be used on either the iPhone or the Mac, without needing separate files.

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


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)

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);

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.