Wednesday, June 1, 2011

How to create a UIImage with a gradient from one or more UIColor

I recently needed to create a very specific progress bar not provided "as is" in the iOS SDK.
"The progress bar have an evolving background, a text label in foreground and an animation as the download/upload progresses. It must also be possible to tap on the progress bar like on a button.".

Solving this issue is pretty simple actually; you only need to use two overlapping buttons, one for the background and another for both the text label and the progression image. The latter has a clearColor background, at least for the "not yet filled" part of the progress image of course.