本文介紹一個(gè)用CADisplayLink實(shí)現(xiàn)一個(gè)簡(jiǎn)單的ContinueLabel。
1、CADisplayLink
CADisplayLink是一個(gè)能讓我們以和屏幕刷新率同步的頻率將特定的內(nèi)容畫到屏幕上的定時(shí)器類,iOS設(shè)備的屏幕刷新頻率(FPS)是60Hz褐捻,因此CADisplayLink的默認(rèn)調(diào)用周期是每秒60次,這個(gè)周期可以通過(guò)frameInterval屬性設(shè)置。
主要方法:
_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateNumber)];
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
2预明、NSNumberFormatter
NSNumberFormatter用于格式化輸出NSNumber;
主要屬性:
- numberStyle
NSNumberFormatter *numberF = [NSNumberFormatter new];
numberF.locale = [NSLocale localeWithLocaleIdentifier:@"ZH_CN"];
// numberF.formatWidth = 15;//15位輸出,不足補(bǔ) *
NSNumber *number = @12345.6789;
numberF.numberStyle = NSNumberFormatterDecimalStyle;//小數(shù)形式:12,345.679
NSLog(@"DecimalStyle: %@",[numberF stringFromNumber:number]);
numberF.numberStyle = NSNumberFormatterCurrencyStyle;//貨幣形式,中國(guó):¥
NSLog(@"CurrencyStyle: %@",[numberF stringFromNumber:number]);
numberF.numberStyle = NSNumberFormatterPercentStyle;//百分百
NSLog(@"PercentStyle: %@",[numberF stringFromNumber:number]);
numberF.numberStyle = NSNumberFormatterScientificStyle;//科學(xué)計(jì)數(shù)
NSLog(@"ScientificStyle: %@",[numberF stringFromNumber:number]);
numberF.numberStyle = NSNumberFormatterSpellOutStyle;//全拼,中國(guó)是 一萬(wàn)兩千...
NSLog(@"SpellOutStyle: %@",[numberF stringFromNumber:number]);
numberF.numberStyle = NSNumberFormatterOrdinalStyle;//序號(hào),第...,四舍五入
NSLog(@"OrdinalStyle: %@",[numberF stringFromNumber:number]);
numberF.numberStyle = NSNumberFormatterCurrencyISOCodeStyle;
NSLog(@"CurrencyISOCodeStyle: %@",[numberF stringFromNumber:number]);
- 其它屬性
zeroSymbol:number等于零時(shí)的樣式;
decimalSeparator:小數(shù)點(diǎn)的樣式耙箍;
positivePrefix/positiveSuffix撰糠、negativePrefix/negativeSuffix:正數(shù)/負(fù)數(shù)的前綴/后綴;
minimumFractionDigits:小數(shù)位最少位數(shù);
maximumFractionDigits:小數(shù)位最多位數(shù)辩昆;
roundingIncrement:四舍五入的增量值阅酪,比如以10為進(jìn)位值,那么156就進(jìn)位為160,154進(jìn)位為150;
其它屬性還有很多汁针,大家可以自己嘗試...
3术辐、最后
show me the code