我正在尝试为 uilabel 上的背景颜色设置动画以实现“淡入淡出”效果。我的代码如下所示:
UILabel *lbl = ...
UIColor *oldCol = lbl.backgroundColor;
lbl.backgroundColor = [UIColor blueColor];
[UIView animateWithDuration:1.0 animations:^(void) {
lbl.backgroundColor = oldCol;
}];
但它会立即恢复到原来的颜色。我还尝试了以下方法来隔离问题:
lbl.backgroundColor = [UIColor blueColor];
[UIView animateWithDuration:1.0 animations:^(void) {
lbl.backgroundColor = [UIColor greenColor];
}];
它立即变为绿色。有什么想法吗?
最佳答案
UILabel 的背景颜色不可设置动画。参见 How to animate the background color of a UILabel?寻找可能的解决方法。
关于iphone - 尝试在 uilabel 上设置背景颜色动画以实现 'fade' 效果,但它会立即应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5958466/