POPAnimatableProperty *prop = [POPAnimatableProperty propertyWithName:@"countdown" initializer:^(POPMutableAnimatableProperty *prop) {
prop.writeBlock = ^(id obj,const CGFloat values[])
{
NSLog(@"%d",(int)values[0]);
NSString *timestring = [NSString stringWithFormat:@"%02d:%02d:%02d",(int)values[0]/60,(int)values[0]%60,(int)(values[0]*100)%100];
_lblTest.attributedText = [self formatterTime:timestring];
};
}];
POPBasicAnimation *anBasic = [POPBasicAnimation linearAnimation]; //秒表当然必须是线性的时间函数
anBasic.property = prop; //自定义属性
anBasic.fromValue = @(1*60); //从0开始
anBasic.toValue = @(0); //180秒
anBasic.duration = 1*60; //持续3分钟
anBasic.beginTime = CACurrentMediaTime(); //延迟1秒开始
[_lblTest pop_addAnimation:anBasic forKey:@"countdown"];
}
- (NSMutableAttributedString *)formatterTime:(NSString *)currentString
{
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc]initWithString:currentString];
for (NSInteger i = 0; i<3; i++)
{
[attribute addAttributes:@{
NSBackgroundColorAttributeName:[UIColor redColor],
NSForegroundColorAttributeName:[UIColor whiteColor],
}
range:NSMakeRange(3*i, 2)];
}
return attribute;
}
@end
![](https://images2015.cnblogs.com/blog/457309/201509/457309-20150924171936319-1728589777.gif)