Matt Gemmell

My new book CHANGER is out now!

An action-adventure novel — book 1 in the KESTREL series.

★★★★★ — Amazon

NSColor Contrasting Label Extensions

Development & Source 1 min read

A quick Cocoa source code post. This one is simple: it’s a category on NSColor which returns another NSColor for use when drawing label text on top of the receiver. Either white or black is returned, depending on which will have most visual contrast with the receiver’s color. In the event of the receiver’s colorspace not being converted to RGB, black is returned by default.

Download the source code (includes a sample app, as always). This code came about due to a conversation I was having today with Iain, so cheers to the man himself for that.