开发者

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?


  1. Add quartzCore as a framework
  2. Add an import QuartzCore/QuartzCore.h
  3. 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];
     }
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜