簡(jiǎn)單實(shí)現(xiàn)支持點(diǎn)贊數(shù)字動(dòng)畫(huà)的SPScrollNumLabel
Github:SPScrollNumLabel
如果你覺(jué)得幫助到你了亚皂,希望給鶸一個(gè)Star勃救,謝謝
博客
如果你發(fā)現(xiàn)任何問(wèn)題,請(qǐng)一定要給我拍磚趋惨,謝謝
項(xiàng)目效果
Ver 0.0.2
Ver 0.0.1
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;
- 設(shè)置目標(biāo)數(shù)字
- 設(shè)置數(shù)字滾動(dòng)的動(dòng)畫(huà)時(shí)間
- 設(shè)置為普通的
UILabel
使用 - 設(shè)置是否為
center
屬性優(yōu)先布局,針對(duì)只設(shè)置foo.center
的情況,詳情見(jiàn)Demo - 數(shù)字增加方法
- 數(shù)字減少方法
設(shè)置
- 對(duì)文字及字體顏色等常見(jiàn)參數(shù)的設(shè)置坠非,直接通過(guò)UILabel的參數(shù)設(shè)置即可.
- 輸入數(shù)字支持targetNum及text兩種屬性輸入
- targetNumber及text的輸入,都請(qǐng)放在字體屬性設(shè)置完成后
注意點(diǎn):如果輸入的文字為中文果正,請(qǐng)不要設(shè)置Label的backgroundColor屬性炎码,否則無(wú)法正常顯示
純代碼
- 設(shè)置frame時(shí),如果size屬性的寬不能適應(yīng)展示寬度,都會(huì)自動(dòng)調(diào)整,如果size屬性的高度不能容納展示高度秋泳,會(huì)自動(dòng)調(diào)整潦闲,能容納則不做任何處理
-
targetNumber
的賦值,請(qǐng)務(wù)必放在配置參數(shù)的最后
CGRect screenBounds = [UIScreen mainScreen].bounds;
SPScrollNumLabel *num = [[SPScrollNumLabel alloc] initWithFrame:(CGRect){CGPointMake(screenBounds.size.width/2 - 50, 100),CGSizeMake(2, 100)}];
// 設(shè)置frame時(shí)
// 如果size屬性的寬不能適應(yīng)展示寬度迫皱,都會(huì)自動(dòng)調(diào)整
// 如果size屬性的高度不能容納展示高度歉闰,會(huì)自動(dòng)調(diào)整,能容納則不做任何處理
// 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賦值 需要設(shè)置是否中心點(diǎn)優(yōu)先
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];
// 屬性配置完成后和敬,賦值 默認(rèn)為0
centerLabel.text = @"998";
// 如果想當(dāng)做普通的UILabel用 比如特殊值"1千"等 打開(kāi)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 = @"我可以當(dāng)普通label用哦";
[commonLabel sizeToFit];
commonLabel.center = CGPointMake(screenBounds.size.width/2, commonLabel.frame.size.height/2+34);
xib
xib支持直接設(shè)置,你可以將必要的參數(shù)在這里直接設(shè)置:顏色戏阅、字體昼弟、動(dòng)畫(huà)時(shí)間、是否是個(gè)普通Label奕筐、動(dòng)畫(huà)翻轉(zhuǎn)時(shí)間
如何應(yīng)用
使用pod或者直接拖拽相應(yīng)文件夾到你的工程下
pod 'SPScrollNumLabel' ,'~> 0.0.2'
20171124 Ver.0.0.2:支持label.text
的直接賦值
20171123 Ver.0.0.1
Enjoy It