【发布时间】:2018-03-29 00:55:44
【问题描述】:
我正在尝试从左到右逐步更改 UILabel 的文本颜色。我发现我可以使用 UIView 的动画:
[UIView transitionWithView:_label duration:1 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
_label.textColor = [UIColor redColor];
} completion:nil];
但问题是我的情况没有选择:从左到右逐步进行。
然后我找到了一种通过调用逐字母更改文本颜色的方法:
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(yourSelector) userInfo:nil repeats:NO];
- (void)yourSelector
{
[_string setAttributes:@{NSForegroundColorAttributeName: [UIColor redColor]} range:NSMakeRange(_index, 1)];
[_label setAttributedText:_string];
_index++;
}
但这里的问题是,我希望动画更像一个字母一个字母,但每个字母也有动画,就像有两个不同颜色的标签放置在同一位置(黑色覆盖红色)并且只是为蒙版制作动画从左到右隐藏黑色标签,使红色标签逐渐显示。
那么有没有办法做到这一点?
【问题讨论】:
-
啊,你想让它像一个进度条吗?不是“逐个字母”
标签: ios objective-c animation text uilabel