之前看到网上用AnchorPoint(锚点)或者用定时器一个一个的显示,利用锚点的弊端是当底部是图片的话遮层的颜色值不容易调试,用定时器的话比较繁琐,为了方便 我用
NSMutableAttributedString这一特性,通过改变字体的颜色值来达到文字依次显示的效果.下面是关键的代码
-(void)finishAnimation
{
for (int i = 0; i < [self.textLabel.text length]; i++)
{
[self performSelector:@selector(setCoreLabel:) withObject:@(i + 1) afterDelay:(i + 1)* 0.06];
}
[self performSelector:@selector(setCoreBottomLabel) withObject:nil afterDelay:[self.textLabel.text length]* 0.08];
}
-(void)setCoreLabel:(NSNumber *)number
{
NSRange range = NSMakeRange(0, [number integerValue]);
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:self.textLabel.text];
[attribute addAttributes: @{NSForegroundColorAttributeName:[UIColor whiteColor]} range:range];
[self.textLabel setAttributedText:attribute];
}
我这是在登录页添加动态启动图用的,如果要异步的话,可以选择GCD去实现异步