A few weeks back, Vincent Iadevaia, the Lead Designer at Shelby.tv, provided me with some designs that required the use of a gradient on multiple UI elements. We decided it would be best to implement the gradient programmatically for each UI element, since this required less assets, and therefore, lessen the size of the iPhone app’s executable file.
In my quest to make this gradient, I found out that many issues arose when using the toll-free bridge between CFColorRef and UIColor. These issues were seemingly related to how ARC manages memory - the CFColorRef declarations and methods that depended on their values (e.g., CFArrayAppendValue, CGGradientRef) were being released from memory too quickly.
Below is a gist that anyone can include in a subclassed-UIView’s implementation file to achieve a programmatic, bridge-less, vertical, linear gradient in iOS 4+ using ARC.
(Tumblr Dashboard readers, view the gist here)
A visual example: