Skip to content
jklundell edited this page Jul 2, 2012 · 4 revisions

UIButton's rounded-rect style is handy and easy to use, but it's pretty boring. You can fix that by replacing the built-in style with images, but it's tedious at best (and worse for some of us) to build those images.

LCGradientButton is a fairly straightforward extension of UIButton for creating nice looking rounded-rect buttons with a color gradient and shadow. It has a provision for using an image instead of the button text, and assorted mechanisms for controlling the color gradient, button border, button radius, etc. And of course the underlying UIButton properties and methods remain available.

To use LCGradientButton, copy LCGradientButton.h & LCGradientButton.m into your project. You'll also need QuartzCore.framework.

The sample project shows how to use LCGradientButton from a xib or programmatically. In the xib, start with a UIButton, change its class to LCGradientButton, adjust your title colors (the sample uses white for all states except disabled, where it uses light gray), and you're off to the races.

If all your buttons are the same color, use setDefaultLowColor:highColor:textColor: before any buttons are instantiated to avoid having to set colors for every button.

LCGradientButton makes at least one iOS 5+ call; see Issue #1 for a workaround for earlier versions.

Use it freely, but please reciprocate with bug fixes and enhancements.

Clone this wiki locally