Glowing code taken from: Creating a Glow Effect for UILabel and UIButton
First, you'll need to import the QuartzCore Framework:
#import <QuartzCore/QuartzCore.h>
When you create a button (or in viewDidLoad
, depends on your code structure) add
this code:
UIColor *color = button.currentTitleColor;
button.titleLabel.layer.shadowColor = [color CGColor];
button.titleLabel.layer.shadowRadius = 4.0f;
button.titleLabel.layer.shadowOpacity = .9;
button.titleLabel.layer.shadowOffset = CGSizeZero;
button.titleLabel.layer.masksToBounds = NO;
You'll need to watch for two events: UIControlEventTouchDown
and UIControlEventTouchUpInside
In UIControlEventTouchDown
handler you'll add the code:
UIColor *color = [UIColor clearColor];
button.titleLabel.layer.shadowColor = [color CGColor];
And in UIControlEventUpInside
handler you'll add the code:
UIColor *color = button.currentTitleColor;
button.titleLabel.layer.shadowColor = [color CGColor];
Again details of implementation depend on whether you create button programmaticaly or via Interface Builder but i'm sure you'll be able to figure this out from here on.
EDIT: for a custom button simply adding the following code should work:
[button setImage:[UIImage imageNamed:@"buttonWithGlow.png"]
forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"buttonWithNoGlow.png"]
forState:UIControlStateHighlighted];