Navigation Menu

Skip to content

Tr2e/SPScrollNumLabel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SPScrollNumLabel

Version license 996.icu

项目中应用效果

项目应用效果

Ver 0.0.2

Text效果

Ver 0.0.1

Demo效果

Api

@property (nonatomic, assign) IBInspectable NSInteger targetNumber;// default is 0
@property (nonatomic, assign) IBInspectable CGFloat animateDuration;// default is 0.25
@property (nonatomic, assign) IBInspectable BOOL isCommonLabel;// default is NO
@property (nonatomic, assign) BOOL centerPointPriority;// default is NO
- (void)increaseNumber:(NSInteger)increasedNum;
- (void)decreaseNumber:(NSInteger)decreasedNum;
  • 设置目标数字
  • 设置数字滚动的动画时间
  • 设置为普通的UILabel使用
  • 设置是否为center属性优先布局,针对只设置foo.center的情况,详情见Demo
  • 数字增加方法
  • 数字减少方法

设置

  1. 对文字及字体颜色等常见参数的设置,直接通过UILabel的参数设置即可.
  2. 输入数字支持targetNum及text两种属性输入
  3. targetNumber及text的输入,都请放在字体属性设置完成后

注意点:如果输入的文字为中文,请不要设置Label的backgroundColor属性,否则无法正常显示

纯代码

  1. 设置frame时,如果size属性的宽不能适应展示宽度,都会自动调整,如果size属性的高度不能容纳展示高度,会自动调整,能容纳则不做任何处理
  2. targetNumber的赋值,请务必放在配置参数的最后
CGRect screenBounds = [UIScreen mainScreen].bounds;
SPScrollNumLabel *num = [[SPScrollNumLabel alloc] initWithFrame:(CGRect){CGPointMake(screenBounds.size.width/2 - 50, 100),CGSizeMake(2, 100)}];
    
    // 设置frame时
    // 如果size属性的宽不能适应展示宽度,都会自动调整
    // 如果size属性的高度不能容纳展示高度,会自动调整,能容纳则不做任何处理
    // num.frame = (CGRect){CGPointMake(screenBounds.size.width/2 - 50, 100),CGSizeMake(2, 100)};
    
// 字体属性,直接赋值
num.textColor = [[UIColor whiteColor] colorWithAlphaComponent:0.5];
num.font = [UIFont systemFontOfSize:40 weight:UIFontWeightBold];
num.backgroundColor = [[UIColor purpleColor] colorWithAlphaComponent:0.4];
    
    
// 如果采用center赋值 需要设置是否中心点优先
SPScrollNumLabel *centerLabel = [[SPScrollNumLabel alloc] init];
centerLabel.center = CGPointMake(screenBounds.size.width/2, 250);
centerLabel.centerPointPriority = YES;
centerLabel.textColor = [[UIColor whiteColor] colorWithAlphaComponent:0.5];
centerLabel.font = [UIFont systemFontOfSize:35 weight:UIFontWeightThin];
centerLabel.backgroundColor = [[UIColor blueColor] colorWithAlphaComponent:0.4];
// 属性配置完成后,赋值 默认为0
centerLabel.text = @"998";
    
// 如果想当做普通的UILabel用 比如特殊值"1千"等 打开isCommonLabel 直接按照UILabel的使用即可
SPScrollNumLabel *commonLabel = [[SPScrollNumLabel alloc] init];
commonLabel.isCommonLabel = YES;
commonLabel.textColor = [[UIColor whiteColor] colorWithAlphaComponent:0.5];
commonLabel.font = [UIFont systemFontOfSize:35 weight:UIFontWeightThin];
commonLabel.backgroundColor = [[UIColor blueColor] colorWithAlphaComponent:0.4];
commonLabel.text = @"我可以当普通label用哦";
[commonLabel sizeToFit];
commonLabel.center = CGPointMake(screenBounds.size.width/2, commonLabel.frame.size.height/2+34);

xib

xib支持直接设置,你可以将必要的参数在这里直接设置:颜色字体动画时间是否是个普通Label动画翻转时间 demo 1 demo 2

如何应用

使用pod或者直接拖拽相应文件夹到你的工程下

pod 'SPScrollNumLabel' ,'~> 0.0.2'

20171124 ver 0.0.2:支持label.text的直接赋值

20171123 ver 0.0.1


Enjoy It