对数字变化添加动画

对于那种数字变化需要带动画效果的,如下

可以用UICountingLabel来处理,地址为

https://github.com/dataxpress/UICountingLabel

但github上只能处理整数和不带分隔符的浮点数,若想使数字加上千分位分隔符,则需要做一些处理。
在UICountingLabel.h上

在UICountingLabel.m上的setTextValue中添加

代码为

if (self.positiveFormat.length > 0) { //带千分位样式
    NSString *str = [NSString stringWithFormat:self.format,value];
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
    formatter.numberStyle = NSNumberFormatterDecimalStyle;
    [formatter setPositiveFormat:self.positiveFormat];
    self.text = [NSString stringWithFormat:@"%@",[formatter stringFromNumber:[NSNumber numberWithFloat:[str floatValue]]]];
}

然后再使用时,可以如下

UICountingLabel *lab = [[UICountingLabel alloc]initWithFrame:CGRectMake(10, 50, 200, 50)];
lab.font = [UIFont systemFontOfSize:24.0];
lab.textColor = [UIColor brownColor];
//设置格式,保留两位小数
lab.format = @"%.2f";
//设置分隔符样式
lab.positiveFormat = @"###,##0.00";
[lab countFrom:0.00 to:9091.64 withDuration:1.0f];
[self addSubview:lab];

效果就是篇首的样子

转载于:https://www.cnblogs.com/Apologize/p/5764889.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值