I have an UIButton which is a logo. This logo button will glow on forever but will stop glowing on touch.It is like a glowing animation.
Is there any suggestions?>
Here is my answer....
Using categories
/* ****FAQ?
1.how to add glow effect on uibutton?
[UIButton glowUIButton:playButton];
2.how to remove effect on uibutton?
[UIButton removeGlowUIButton:playButton];
Ends*** */
#import
@interface UIButton (BlinkEffect)
//blink effect category
+( void) glowUIButton:(UIButton *)inputButton;
//remove blink effect
+(void) removeGlowUIButton:(UIButton *)inputButton;
@end
#import "UIButton+BlinkEffect.h"
@implementation UIButton (BlinkEffect)
+(void) glowUIButton:(UIButton *)inputButton
{
//add blink effect
CALayer *viewLayer = inputButton.layer;
viewLayer.shadowOffset = CGSizeMake(0,0);
CGFloat radius = CGRectGetWidth(inputButton.bounds)/2.0;
viewLayer.shadowColor = [[UIColor whiteColor] CGColor];
viewLayer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(-7,-5.5, 2.5 * (radius), 2.5 * radius) cornerRadius:radius].CGPath;
viewLayer.shadowRadius = 5.0f;
viewLayer.shadowOpacity = 1.0f;
//Let's animate it while we're at it.
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
animation.duration =0.7;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.fromValue = [NSNumber numberWithFloat:1.0];
animation.toValue = [NSNumber numberWithFloat:0.0];
animation.autoreverses = YES;
animation.repeatCount = 1.0 / 0.0;
[viewLayer addAnimation:animation forKey:@"shadowOpacity"];
}
+(void)removeGlowUIButton:(UIButton *)inputButton
{
CALayer *viewLayer = inputButton.layer;
viewLayer.shadowColor = [[UIColor clearColor] CGColor];
[viewLayer removeAnimationForKey:@"shadowOpacity"];
}
@end