iPhone UILabel animation
I have a UILabel an开发者_如何学Pythond when the value change in the label, I want to highlight it's background color from another color and exists for 2,3 seconds and get back to normal color.
Anyone have an idea how to do this?
- Add quartzCore as a framework
- Add an import QuartzCore/QuartzCore.h
Use this code
- (void) initController { UIButton *myButton = [view viewWithTag:1]; // Just reference the button you have [myButton addTarget:self action:@selector(animateLabel) forControlEvents:UIControlEventTouchUpInside]; } - (void) animateLabel { CABasicAnimation* highlightAnim = [CABasicAnimation animationWithKeyPath:@"backgroundColor"]; highlightAnim.toValue = (id)[UIColor blueColor].CGColor; highlightAnim.duration = 2; // In seconds highlightAnim.autoreverses = YES; // If you want to it to return to the normal color [label.layer addAnimation:highlightAnim forKey:nil]; }
精彩评论