iOS-支持點贊數字動畫的SPScrollNumLabel

簡單實現支持點贊數字動畫的SPScrollNumLabelgit

Github:SPScrollNumLabel
若是你以爲幫助到你了,但願給鶸一個Star,謝謝
簡書
博客
若是你發現任何問題,請必定要給我拍磚,謝謝github

項目效果
timelineDemo佈局

Ver 0.0.2
text.gif字體

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屬性,不然沒法正常顯示atom

純代碼

  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動畫翻轉時間
XibDemo1
XibDemo2spa

如何應用

使用pod或者直接拖拽相應文件夾到你的工程下code

pod 'SPScrollNumLabel' ,'~> 0.0.2'

20171124 Ver.0.0.2:支持label.text的直接賦值blog

20171123 Ver.0.0.1rem


Enjoy It

相關文章
相關標籤/搜索