我有多个带有lightGray背景颜色的标签,我想将它们的颜色设置为UIColor.clear:
UIView.animate(withDuration: 5.0, animations: {
self.titleLabel.backgroundColor = UIColor.clear
self.dateLabel.backgroundColor = UIColor.clear
self.categoryLabel.backgroundColor = UIColor.clear
})
但颜色瞬间变化!为什么呢?
答案 0 :(得分:1)
好吧,我不知道为什么苹果不允许动画背景颜色变化的原因,但这是另一个stackoverflow's post提供的解决方案,如下所示:
#import <QuartzCore/QuartzCore.h>
...
theLabel.layer.backgroundColor = [UIColor whiteColor].CGColor;
[UIView animateWithDuration:2.0 animations:^{
theLabel.layer.backgroundColor = [UIColor greenColor].CGColor;
} completion:NULL];
另一个黑客是你在UIView
后面UILabel
,并给UILabel
清晰的颜色,这样你就可以设置UIView
的颜色变化动画