RMDisplayLabel.m 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // RMDisplayLabel.m
  3. // BezierLoaders
  4. //
  5. // Created by Mahesh on 1/30/14.
  6. // Copyright (c) 2014 Mahesh. All rights reserved.
  7. //
  8. #import "RMDisplayLabel.h"
  9. @interface RMDisplayLabel()
  10. @property(nonatomic, assign)CGFloat toValue;
  11. @property(nonatomic, assign)CGFloat fromValue;
  12. @property(nonatomic, strong)NSTimer *countTimer;
  13. @end
  14. @implementation RMDisplayLabel
  15. - (id)initWithFrame:(CGRect)frame
  16. {
  17. self = [super initWithFrame:frame];
  18. if (self) {
  19. // Initialization code
  20. }
  21. return self;
  22. }
  23. /*
  24. // Only override drawRect: if you perform custom drawing.
  25. // An empty implementation adversely affects performance during animation.
  26. - (void)drawRect:(CGRect)rect
  27. {
  28. // Drawing code
  29. }
  30. */
  31. - (void)updateValue:(CGFloat)value
  32. {
  33. self.toValue = floor((value * 100));
  34. self.fromValue = [self.text floatValue];
  35. self.countTimer = [NSTimer scheduledTimerWithTimeInterval:0.04 target:self selector:@selector(addUpTimer) userInfo:nil repeats:YES];
  36. // Change the text
  37. self.text = [NSString stringWithFormat:@"%i",(int)(value * 100)];
  38. }
  39. -(void)addUpTimer {
  40. self.fromValue++;
  41. if((int)self.fromValue > (int)self.toValue)
  42. {
  43. [self.countTimer invalidate];
  44. self.countTimer = nil;
  45. }
  46. self.text = [NSString stringWithFormat:@"%d", (int)self.fromValue];
  47. }
  48. @end