iOS与macOS中一款优雅的数字/金额增减动效组件
iOS与macOS中一款优雅的数字/金额增减动效控件
下载DEMO后,将子文件夹PPCounter拖入到项目中, 导入头文件 PPCounter.h 开始使用
firstpod 'PPCounter',:git => 'https://github.com/jkpang/PPCounter.git'
thenpod install 或 pod install --no-repo-update
如果发现pod search PPCounter 不是最新版本,在终端执行pod setup命令更新本地spec镜像缓存(时间可能有点长),重新搜索就OK了
....
[label pp_fromNumber:0 toNumber:100 duration:1.5 animationOptions:PPCounterAnimationOptionCurveEaseOut format:^NSString *(CGFloat number) {
// 此处自由拼接内容
return [NSString stringWithFormat:@"%.2f",number];
} completion:^{
// 完成的回调
}];
....
[label pp_fromNumber:0 toNumber:100 duration:1.5 animationOptions:PPCounterAnimationOptionCurveEaseOut attributedFormat:^NSAttributedString *(CGFloat number) {
// 此处自由设置富文本属性的内容
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@""];
return attributedString;
} completion:^{
// 完成的回调
}];
....
[button pp_fromNumber:0 toNumber:100 duration:1.5 animationOptions:PPCounterAnimationOptionCurveEaseOut format:^NSString *(CGFloat number) {
// 此处自由拼接内容
return [NSString stringWithFormat:@"%.2f",number];
} completion:^{
// 完成的回调
}];
....
[button pp_fromNumber:0 toNumber:100 duration:1.5 animationOptions:PPCounterAnimationOptionCurveEaseOut attributedFormat:^NSAttributedString *(CGFloat number) {
// 此处自由设置富文本属性的内容
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@""];
return attributedString;
} completion:^{
// 完成的回调
}];
以上就是PPCounter的简单使用方法,更详细的用法请看demo
[[PPCounterEngine counterEngine] fromNumber:0
toNumber:999
duration:2.f
animationOptions:PPCounterAnimationOptionCurveEaseOut
currentNumber:^(CGFloat number) {
// lable控件
self.numberLabel.stringValue = [NSString stringWithFormat:@"%ld",(NSInteger)number];
} completion:^{
// 计数完成的回调
self.numberLabel.textColor = [NSColor redColor];
}];
===
PPCounter 使用 MIT 许可证,详情见 LICENSE 文件。