FlickerNumber 1.1

FlickerNumber 1.1

测试测试过的
Lang语言 Obj-CObjective C
许可证 MIT
发布上次发布2015年11月

DeJohn Dong维护。



  • 作者
  • DeJohn Dong

像支付宝使用的 UILabel 分类那样闪烁一个数字。如果使用高级方法,则可能很奇妙。

效果

安装

作为替代方案,您可以直接将 FlickerNumber/Classes 中的文件拖拽到您自己的项目中。

使用

要运行示例项目,请先从仓库中复制,然后在项目目录中运行 pod install

在您的项目中引入 UILabel+FlickerNumber.h

然后您可以在任何初始化的 UILabel 中使用分类方法来实现闪烁数字的效果。

例如

@property (nonatomic, weak) IBOutlet UILabel *lblFlicker; //for a xib label

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    if([self.title isEqualToString:@"Flicker A Integer Number"]){
        [self.lblFlicker dd_setNumber:@(7654321)];
    }else if([self.title isEqualToString:@"Flicker A Float Number"]){
        [self.lblFlicker dd_setNumber:@(123.982)];
    }else if([self.title isEqualToString:@"Flicker A Format Number"]){
        [self.lblFlicker dd_setNumber:@(75.212) format:@"%.2f"];
    }else if([self.title isEqualToString:@"Flicker A Attribute Number"]){
        id attributes = [NSDictionary dictionaryWithAttribute:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f]}
                                                     range:NSMakeRange(0, 1)];
        [self.lblFlicker dd_setNumber:@(123.45) attributes:attributes];
    }else{
        id attributes = @[[NSDictionary dictionaryWithAttribute:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f]}
                                                       range:NSMakeRange(0, 1)],
                          [NSDictionary dictionaryWithAttribute:@{NSForegroundColorAttributeName:[UIColor redColor]}
                                                       range:NSMakeRange(1, 3)]];
        [self.lblFlicker dd_setNumber:@(123.45) duration:1.0f format:@"%.2f" attributes:attributes];
    }
}

方法

/**
 *  Flicker a number without other effects.
 *
 *  @param number    The number for flicker animation, can't be `nil`.
 */
- (void)fn_setNumber:(NSNumber *)number;

/**
 *  Flicker a number with number-formatter style. You can use the `NSNumberFormatterCurrencyStyle` number-formatter style, the number will flicker animation as `$1,023.12`.
 *
 *  @param number    The number for flicker animation.
 *  @param formatter The number-formatter style. If this parameter is `nil`, the method should use the default number-formatter style -- `NSNumberFormatterDecimalStyle`, so `1000000` will be '1,000,000'.
 */
- (void)fn_setNumber:(NSNumber *)number
           formatter:(nullable NSNumberFormatter *)formatter;

/**
 *  Flicker a number in during time.
 *
 *  @param number    The number for flicker animation.
 *  @param duration  The flicker animation during time, can't be a minus.
 */
- (void)fn_setNumber:(NSNumber *)number
            duration:(NSTimeInterval)duration;

/**
 *  Flicker a number in during time with number-formatter style.
 *
 *  @param number    The number for flicker animation.
 *  @param duration  The flicker animation during time.
 *  @param formatter The number-formatter style.
 */
- (void)fn_setNumber:(NSNumber *)number
            duration:(NSTimeInterval)duration
           formatter:(nullable NSNumberFormatter *)formatter;

/**
 *  Flicker a number with string-format style. like this: `Today's income: $200.00`.
 *
 *  @param number    The number for flicker animation.
 *  @param formatStr The string-format String. If you set this parameter is `nil`, the method is same to `fn_setNumber:`.
 */
- (void)fn_setNumber:(NSNumber *)number
              format:(nullable NSString *)formatStr;

/**
 *  Flicker a number with string-format String & number-formatter style.
 *
 *  @param number    The number for flicker animation.
 *  @param formatStr The string-format String.
 *  @param formatter The number-formatter style.
 */
- (void)fn_setNumber:(NSNumber *)number
              format:(nullable NSString *)formatStr
           formatter:(nullable NSNumberFormatter *)formatter;


/**
 *  Flicker a number with attributed(s) property.
 *
 *  @param number The number for flicker animation.
 *  @param attrs  The attributed number set(a dictionary OR array of dictionaries), character attributes for text. Only can attributed the number because there are no string-format String. Use this parameter the number text can be colorful and wonderful. If you set this parameter is `nil`, the same to method `fn_setNumber:`.
 */
- (void)fn_setNumber:(NSNumber *)number
          attributes:(nullable id)attrs;

/**
 *  Flicker a number with number-formatter style & attributed(s) property.
 *
 *  @param number    The number for flicker animation.
 *  @param formatter The number-formatter style.
 *  @param attrs     The attributed number set(a dictionary OR array of dictionaries).
 */
- (void)fn_setNumber:(NSNumber *)number
           formatter:(nullable NSNumberFormatter *)formatter
          attributes:(nullable id)attrs;

/**
 *  Flicker a number with string-format String & attributed(s) property.
 *
 *  @param number    The number for flicker animation.
 *  @param formatStr The string-format String.
 *  @param attrs     The attributed string set(a dictionary OR array of dictionaries). You can attributed(s) the number or string-format String.
 */
- (void)fn_setNumber:(NSNumber *)number
              format:(nullable NSString *)formatStr
          attributes:(nullable id)attrs;

/**
 *  Flicker a number in dafault during time(1.0s) with all effects.
 *
 *  @param number    The number for flicker animation.
 *  @param formatStr The string-format String.
 *  @param formatter The number-formatter style.
 *  @param attrs     The attributed string set(a dictionary OR array of dictionaries).You can attributed(s) the number or string-format String.
 */
- (void)fn_setNumber:(NSNumber *)number
              format:(nullable NSString *)formatStr
           formatter:(nullable NSNumberFormatter *)formatter
          attributes:(nullable id)attrs;

/**
 *  Flicker a number in during time with string-format String.
 *
 *  @param number    The number for flicker animation.
 *  @param duration  The flicker animation during time.
 *  @param formatStr The string-format String.
 */
- (void)fn_setNumber:(NSNumber *)number
            duration:(NSTimeInterval)duration
              format:(nullable NSString *)formatStr;

/**
 *  Flicker a number in during time with string-format String & number-formatter style.
 *
 *  @param number    The number for flicker animation.
 *  @param duration  The flicker animation during time.
 *  @param formatStr The string-format String.
 *  @param formatter The number-formatter style.
 */
- (void)fn_setNumber:(NSNumber *)number
            duration:(NSTimeInterval)duration
              format:(nullable NSString *)formatStr
           formatter:(nullable NSNumberFormatter *)formatter;

/**
 *  Flicker a number in during time with attributed(s) property.
 *
 *  @param number   The number for flicker animation.
 *  @param duration The flicker animation during time.
 *  @param attrs    The attributed number set(a dictionary OR array of dictionaries).
 */
- (void)fn_setNumber:(NSNumber *)number
            duration:(NSTimeInterval)duration
          attributes:(nullable id)attrs;

/**
 *  Flicker a number in during time with attributed(s) property of number & number-formatter style.
 *
 *  @param number    The number for flicker animation.
 *  @param duration  The flicker animation during time.
 *  @param formatter The number-formatter style.
 *  @param attrs     The attributed number set(a dictionary OR array of dictionaries).
 */
- (void)fn_setNumber:(NSNumber *)number
            duration:(NSTimeInterval)duration
           formatter:(nullable NSNumberFormatter *)formatter
          attributes:(nullable id)attrs;

/**
 *  Flicker a number in during time with effects except number-formatter style.
 *
 *  @param number    The number for flicker animation.
 *  @param duration  The flicker animation during time.
 *  @param formatStr The string-format String.
 *  @param attrs     The attributed string set(a dictionary OR array of dictionaries). You can set string-format String OR number attributes both.
 */
- (void)fn_setNumber:(NSNumber *)number
            duration:(NSTimeInterval)duration
              format:(nullable NSString *)formatStr
          attributes:(nullable id)attrs;

/**
 *  Flicker a number in during time with all the effects. You can attributed(s) the number or string-format String. You also can set the number number-fomatter style.
 *
 *  @param number    The number for flicker animation.
 *  @param duration  The flicker animation during time.
 *  @param formatStr The string-format String.
 *  @param formatter The number-formatter style.
 *  @param attrs     The attributed string set(a dictionary OR array of dictionaries).
 */
- (void)fn_setNumber:(NSNumber *)number
            duration:(NSTimeInterval)duration
              format:(nullable NSString *)formatStr
     numberFormatter:(nullable NSNumberFormatter *)formatter
          attributes:(nullable id)attrs;

更新

  • [1.0] 添加了长整型整数或双精度浮点数的闪烁功能。
  • [0.2] 添加了 NSNumberFormatter 功能。
  • [0.1] 添加了闪烁数字工具包。

要求

  • Xcode 7
  • iOS 5.1.1

作者

DeJohn Dong, [email protected]

许可证

FlickerNumber 可以在 MIT 许可下使用。有关更多信息,请参阅 LICENSE 文件。