簡單實現支持點贊數字動畫的SPScrollNumLabelgit
Github:SPScrollNumLabel
若是你以爲幫助到你了,但願給鶸一個Star,謝謝
簡書
博客
若是你發現任何問題,請必定要給我拍磚,謝謝github
項目效果佈局
Ver 0.0.2字體
Ver 0.0.1動畫
@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注意點:若是輸入的文字爲中文,請不要設置Label的backgroundColor屬性,不然沒法正常顯示atom
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支持直接設置,你能夠將必要的參數在這裏直接設置:顏色、字體、動畫時間、是不是個普通Label、動畫翻轉時間spa
使用pod或者直接拖拽相應文件夾到你的工程下code
pod 'SPScrollNumLabel' ,'~> 0.0.2'
20171124 Ver.0.0.2:支持label.text
的直接賦值blog
20171123 Ver.0.0.1rem
Enjoy It