我是CALayer班级的新手,我正在尝试用动画制作渐变色标签, 所以ai见过 CAGradientLayer &的 CABasicAnimation
CAGradientLayer *grad=[CAGradientLayer layer];
grad.frame=self.lbl.bounds;
UIColor *ac1=[UIColor purpleColor];
UIColor *ac2=[UIColor yellowColor];
UIColor *ac3=[UIColor blueColor];
grad.colors=@[(id)[ac2 CGColor],(id)[ac2 CGColor],(id)[ac3 CGColor]];
CABasicAnimation *anim2=[CABasicAnimation animationWithKeyPath:@"colors"];
anim2.toValue=@[(id)ac1.CGColor,(id)ac2.CGColor,(id)ac2.CGColor];
anim2.duration=4.0;
anim2.autoreverses=YES;
anim2.repeatCount=1e100;
[grad addAnimation:anim2 forKey:@"colors"];
[[self.lbl layer] insertSublayer:gradient atIndex:0];
目前它为标签背景设置了动画,我如何将其设置为文本动画?它也没有显示文字??
我不想为此使用一些自定义库。