Simple implementation to support digital animation like SPScrollNumLabel

SPScrollNumLabel If you find it helpful to you, would like to give a Star, thank you blog if you find any problems, please be sure to give me a crack, thank you


timelineDemo

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;Copy the code
  • Set target number
  • Set the animation time of the digital scroll
  • Set to ordinaryUILabeluse
  • Set whether tocenterProperty preference layout for Settings onlyfoo.centerFor details, see Demo
  • Number increment method
  • Digital reduction method

Set up the

Pure code

  1. When setting the frame, if the width of the size attribute does not fit the display width, it will be automatically adjusted; if the height of the size attribute does not fit the display height, it will be automatically adjusted; if the size attribute can accommodate the display height, no processing will be done
  2. targetNumberMake sure to put in the configuration parameterThe last
CGRect screenBounds = [UIScreen mainScreen].bounds; SPScrollNumLabel *num = [[SPScrollNumLabel alloc] initWithFrame:(CGRect){CGPointMake(screenBounds.size.width/2 - 50, 100),CGSizeMake(2, 100)}]; // If the width of the size attribute does not fit the display width, it will be adjusted automatically. Can accommodate does not do any processing / / num frame = (CGRect) {CGPointMake (screenBounds. Size. Width / 2-50, 100), CGSizeMake} (2, 100); / / font properties, direct assignment num. TextColor = [[UIColor whiteColor] colorWithAlphaComponent: 0.5]; num.font = [UIFont systemFontOfSize:40 weight:UIFontWeightBold]; Num. BackgroundColor = [[UIColor purpleColor] colorWithAlphaComponent: 0.4]; // After the attribute is configured, the default value is 0 num. TargetNumber = 512; 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]; SPScrollNumLabel *commonLabel = [[SPScrollNumLabel *commonLabel = [SPScrollNumLabel *commonLabel 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 = @" I can use it as a normal label "; [commonLabel sizeToFit]; commonLabel.center = CGPointMake(screenBounds.size.width/2, commonLabel.frame.size.height/2+34);Copy the code

xib

Xib supports direct Settings, where you can directly set the necessary parameters: color, font, animation time, whether it is a normal Label, animation flip time


XibDemo1




XibDemo2

How to apply

Use POD or drag and drop the corresponding folder into your project

pod 'SPScrollNumLabel'
Copy the code

Enjoy It