Tag: Graphics
Cocoa LCD Screen View
by Warlock on May.25, 2009, under Cocoa
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.
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.
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.

