使用此代码
- (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];
}
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
1352 次 |
| 最近记录: |