You’re working on a custom iPhoneOS view and you want it to use colours from the standard iPhone OS colour palette. Your first impulse is to check the defined colours in UIInterface.h – but there are only a grand total of five colours defined in that header. Your next and probably last impulse is to break out the colour picker and use the eye-dropper tool to sample the exact RGB value from the screen itself.
There are two problems with using an eye-dropper tool. The first problem is that by sampling the on screen pixel value you can only get the composited red, green, blue values; you cannot get the alpha value at all. If the original colour had an alpha value then the final colour you might get will not much the original colour at all. The second problem is that you can’t easily be sure that a colour you sample directly off the screen uses the same colour profile as the original.
I decided instead to use Intruments to probe the application and find out exactly what RGBA colour was being used by UIKit. I modified my project to display the element I wanted to find out the colour of (in my case it was the colour of a UITableView’s section footer label) and then ran the application through Intruments.
After a little trial and error (and some help from Kevin Ballard to work out exactly how to output the RGBA values) I had an Instrument that would display all parameters passed to [UIColor initWithRed:green:blue:alpha] (Screenshot)
As you can see from the screenshot, this works almost too well, with Intruments displaying almost too much information. But it is actually quite easy to narrow down the data to exactly what you’re looking for (screenshot).
Note that you wont get all colours. Just those created via [UIColor initWithRed:green:blue:alpha:] but the same technique can easily be used to probe for colours created via other methods or even via CG functions. It’s also pretty easy to use gdb to break on the relevant symbol and print out the parameters – however once you have this instrument in place it’s really quick and easy to run through an application and capture all colours. You can even export the colours into CSV file for easy manipulation.
You can download the Instrument here, copy it to
~/Library/Application Support/Instruments/PlugIns/Instrumentsand then drag the instrument from Instruments Library into your workflow.