Colors from Hex in Objective-C
Apr 20
EDIT 5/4/12: real men can admit it when they’re wrong— I’ve retooled my approach to use a category on UIColor, hopefully making it easier to use.
I want to tell all you iOS devs about the minorly fantastic thing I’ve created. Here’s you:
“…Y’know, I wish I didn’t have to ALWAYS create colors in my app using an RGB float value. Why can’t I just use hex values? Apple put methods into Objective-C for nearly everything, didn’t they think this one would be a common use case? Also, I don’t like the way I maintain the colors in my app, but I don’t have a real knockout solution. Globals are lame, I don’t want to define the colors in my header, and I DEFINITELY don’t want to maintain a dozen points where I change the screen background to a certain shade of red. Dan, what should I do???”

Fear not, fine citizen… I’m here to help.
I’ve made this here color factory that allows one to create UIColor objects from hex! It doesn’t mind playing rough: 0Xffcc54, #F00BA4, 345667… it doesn’t care, they all work. It creates the colors from a class level method, you don’t even need to instantiate my stupid factory to use it!!! Seriously, it’s a very simple singleton factory— you’re gonna love it.
Here’s how to use it to generate a color somewhere in your app:
Easy right? So that’s how I initially dreamed it up, but I soon found that it became cumbersome to create colors a billion times. I needed some way to access global colors, but many ways of doing that are cumbersome and gross. Here’s what I came up with: I made a singleton object that instantiates a bunch of user defined colors and holds onto them for use across your entire app. This object gets created the first time you call it and just goes wherever you tell it.

I love tacos, can we talk about them for a minute?
Let’s say for the sake of argument that you have a UIViewController in your app called TacoViewController. This view is responsible for displaying a collection of UIImageViews representing a taco in some view controller, but you aren’t exactly sure which shade of brown you should display for the carne asada.
Here’s how you use Color Factory to make your job easier:
Bring Color Factory into your project.An easy way to do that would be cloning my repository HERE and drag ColorFactory.h and ColorFactory.m into your project in Xcode.You’ll notice I’ve loaded a sample scheme in, you can delete that nonsense— it’s just there to show you the way.
Here’s what your ColorFactory.h should resemble:
And then in your .m, initialize your colors in your shared factory like so:
You’ve got your color palette created now, let’s learn how to use it.
here’s SomeViewController.h, where we have 4 UIImageView objects representing the various layers of a taco and a ColorFactory object for our palette:
Finally, we come to the implementation of SomeViewController
…where we initialize our color palette to the shared ColorFactory resource. We then use these colors to fill our taco images with the right colors. Check it out:
I don’t have any taco apps on the market right now, and I don’t think I would create a taco from a collection of UIImageViews but this hopefully gets my point across. We use this class here at Attachments.me for our iPhone app, it really helps to keep text, table cells, backgrounds and so on all cohesive with a singular design. To create the colors, I modified a method written in one of WrightsCS’s posts on stackoverflow. I’m pretty sure this method of singleton creation is thread safe as well.

Questions/comments/solutions/complaints/quandaries/dilemmas?
Once again, the git repo is located here ->Color Factory Repository
—Dan (@DanReedx86)
BONUS: People like cats in the internet, here’s a photo of one of mine. This is Sukoshi, he’s a gemini from the Detroit area and he loves to eat cat food, pea pods, and spiders. Hobbies include being afraid of everything, chasing bugs, and laying in the sun.



3. Choose a Medical Plan that Fits Your Employees
Jesse: “I love my 20% time, I’ve been spending it building a really sick art bike for next year’s Burning Man.”




I know what I like, but I also know that coders are often a strange bird (pictured right). When thinking about the layout of this article I wanted to be careful not to
Fast paced, repetitive, with little or no words? That leaves two choices for optimum accuracy: classical and electronica. Both supergenres hold a wide variety of wildly different styles, there’s something for everyone’s varied taste. Electronica can be split into trance, house, minimalist, dance, dubstep, chiptunes, chipstep, drum n’ bass… the list goes on for days and days. Classical is just as varied. If you’re an aural sponge soaking up soundbytes (like me), I’ve made a few spotify playlists you might enjoy. Here’s one for 
That’s my toolbox of music tools, my philosophy as a coder, and my life’s blood in a nutshell. Take it; 
