效果图:
1.gif
代码:
// 从1跑到10
UICountingLabel* myLabel = [[UICountingLabel alloc] initWithFrame:CGRectMake(10, 10, 200, 40)];
myLabel.method = UILabelCountingMethodLinear;
myLabel.format = @"%d";
[self.view addSubview:myLabel];
[myLabel countFrom:1 to:10 withDuration:3.0];
// make one that counts up from 5% to 10%, using ease in out (the default)
UICountingLabel* countPercentageLabel = [[UICountingLabel alloc] initWithFrame:CGRectMake(10, 50, 200, 40)];
[self.view addSubview:countPercentageLabel];
countPercentageLabel.format = @"%.1f%%";
[countPercentageLabel countFrom:5 to:10];
// 带有逗号
// count up using a string that uses a number formatter
UICountingLabel* scoreLabel = [[UICountingLabel alloc] initWithFrame:CGRectMake(10, 90, 200, 40)];
[self.view addSubview:scoreLabel];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = kCFNumberFormatterDecimalStyle;
scoreLabel.formatBlock = ^NSString* (CGFloat value)
{
NSString* formatted = [formatter stringFromNumber:@((int)value)];
return [NSString stringWithFormat:@"Score: %@",formatted];
};
scoreLabel.method = UILabelCountingMethodEaseOut;
[scoreLabel countFrom:0 to:10000000 withDuration:2.5];
git地址:**https://github.com/dataxpress/UICountingLabel
网友评论