UIView: How to Make Shiny Backgrounds and Other Reusable Styles

When I first started making iPhone apps, I wrote a lot of repetitive code to style interface elements. Certainly, getting comfortable with Interface Builder eases that pain to some degree, but IB won't allow you to take advantage of a lot of available built-in styling features for your interface elements, such as curved corners, drop shadows, and stroked borders. Additionally, you can create beautiful gradient backgrounds in code pretty easily, but the code is somewhat verbose, so it really pays off to find good ways of re-using that kind of code. Also, using a programmatic approach to your app styling can eliminate the production time associated with image-based styles (e.g. custom background images). A lot of common effects used in UIs can be realized without any images whatsoever.

iPhone: How to Dynamically Color a UIImage

In my recent work on Sphericle, there were a few instances where I wanted to use the same image over and over, but colored differently each time. For example, I want to show spheres of different colors on a map; there are 360,000 spheres, each having its own color. I didn't want to draw the sphere algorithmically; I wanted the picture of a sphere to be based on an image, but then colored appropriately. The solution: use a grayscale image of a sphere, then draw a color over it using a color burn blend mode. That's what I want to show you today.