github地址:https://github.com/948080952/DPScrollNumberLabel
实现思路参考我的博客:
一个能够显示最多8位数字的控件,当你改变显示的数字的时,会有一个滚动动画。
使用将DPScrollNumberLabel文件夹中的两个文件复制进工程,论文,在需要使用的地方导入头文件
初始化的方法传人字体大小或是一个字体,不要设置其frame,只需改变其位置即可,因为它是根据字体大小自动计算自身的大小
@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.scrollLabel = [[DPScrollNumberLabel alloc] initWithNumber:@(1) font:[UIFont fontWithName:@'AppleSDGothicNeo-SemiBold' size:40] textColor:[UIColor grayColor] rowNumber:5]; self.scrollLabel.frame = CGRectMake(100, 100, self.scrollLabel.frame.size.width, self.scrollLabel.frame.size.height); [self.view addSubview:self.scrollLabel]; } @end当想要改变其数值时,开题报告,调用下面方法即可,当animated参数为NO时不会播放动画
[self.scrollLabel changeToNumber:@(10) animated:YES];