ViewController.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // ViewController.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/1/14.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "ViewController.h"
  9. #import "SVGA.h"
  10. #import <SDWebImage/SDImageCache.h>
  11. #import "XYScrollNumberLabel.h"
  12. @interface ViewController ()
  13. @property (nonatomic, strong) XYScrollNumberLabel *scrollLabel;
  14. @property (nonatomic, strong)UIButton *addOne;
  15. @property (nonatomic, strong)UIButton *addFive;
  16. @property (nonatomic, strong)UIButton *add100;
  17. @property (nonatomic, strong)UIButton *add500;
  18. @property (nonatomic, strong)UIButton *reduceOne;
  19. @property (nonatomic, strong)UIButton *reduceFive;
  20. @property (nonatomic, strong)UIButton *reduce100;
  21. @property (nonatomic, strong)UIButton *reduce500;
  22. @end
  23. @implementation ViewController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. // Do any additional setup after loading the view.
  27. self.scrollLabel = [[XYScrollNumberLabel alloc] initImageNumberLabelWithNeewMark:YES imageSize:CGSizeMake(20.0f, 28.0f)];
  28. self.scrollLabel.frame = CGRectMake(100, 100, self.scrollLabel.frame.size.width, self.scrollLabel.frame.size.height);
  29. [self.view addSubview:self.scrollLabel];
  30. [self.view addSubview:self.addOne];
  31. [self.view addSubview:self.reduceOne];
  32. [self.view addSubview:self.addFive];
  33. [self.view addSubview:self.reduceFive];
  34. [self.view addSubview:self.add100];
  35. [self.view addSubview:self.reduce100];
  36. [self.view addSubview:self.add500];
  37. [self.view addSubview:self.reduce500];
  38. }
  39. - (void)buttonClicked:(UIButton *)sender {
  40. NSInteger tmp = self.scrollLabel.displayedNumber;
  41. switch (sender.tag) {
  42. case 0:
  43. break;
  44. case 1:
  45. [self.scrollLabel changeToTargetNumber:tmp + 1 duration:0.5 animated:YES];
  46. break;
  47. case 2:
  48. [self.scrollLabel changeToTargetNumber:tmp + 5 duration:0.5 animated:YES];
  49. break;
  50. case 3:
  51. [self.scrollLabel changeToTargetNumber:tmp + 100 duration:0.5 animated:YES];
  52. break;
  53. case 4:
  54. [self.scrollLabel changeToTargetNumber:tmp + 500 duration:0.5 animated:YES];
  55. break;
  56. case 5:
  57. [self.scrollLabel changeToTargetNumber:tmp - 1 animated:YES];
  58. break;
  59. case 6:
  60. [self.scrollLabel changeToTargetNumber:tmp - 5 animated:YES];
  61. break;
  62. case 7:
  63. [self.scrollLabel changeToTargetNumber:tmp - 100 animated:YES];
  64. break;
  65. case 8:
  66. [self.scrollLabel changeToTargetNumber:tmp - 500 animated:YES];
  67. break;
  68. default:
  69. break;
  70. }
  71. }
  72. - (UIButton *)addOne {
  73. if (!_addOne) {
  74. _addOne = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  75. [_addOne setTitle:@"+1" forState:UIControlStateNormal];
  76. _addOne.frame = CGRectMake(70, 230, 100, 20);
  77. _addOne.tag = 1;
  78. [_addOne addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
  79. }
  80. return _addOne;
  81. }
  82. - (UIButton *)addFive {
  83. if (!_addFive) {
  84. _addFive = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  85. [_addFive setTitle:@"+5" forState:UIControlStateNormal];
  86. _addFive.frame = CGRectMake(70, 260, 100, 20);
  87. _addFive.tag = 2;
  88. [_addFive addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
  89. }
  90. return _addFive;
  91. }
  92. - (UIButton *)add100 {
  93. if (!_add100) {
  94. _add100 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  95. [_add100 setTitle:@"+100" forState:UIControlStateNormal];
  96. _add100.frame = CGRectMake(70, 290, 100, 20);
  97. _add100.tag = 3;
  98. [_add100 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
  99. }
  100. return _add100;
  101. }
  102. - (UIButton *)add500 {
  103. if (!_add500) {
  104. _add500 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  105. [_add500 setTitle:@"+500" forState:UIControlStateNormal];
  106. _add500.frame = CGRectMake(70, 320, 100, 20);
  107. _add500.tag = 4;
  108. [_add500 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
  109. }
  110. return _add500;
  111. }
  112. - (UIButton *)reduceOne {
  113. if (!_reduceOne) {
  114. _reduceOne = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  115. [_reduceOne setTitle:@"-1" forState:UIControlStateNormal];
  116. _reduceOne.frame = CGRectMake(170, 230, 100, 20);
  117. _reduceOne.tag = 5;
  118. [_reduceOne addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
  119. }
  120. return _reduceOne;
  121. }
  122. - (UIButton *)reduceFive {
  123. if (!_reduceFive) {
  124. _reduceFive = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  125. [_reduceFive setTitle:@"-5" forState:UIControlStateNormal];
  126. _reduceFive.frame = CGRectMake(170, 260, 100, 20);
  127. _reduceFive.tag = 6;
  128. [_reduceFive addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
  129. }
  130. return _reduceFive;
  131. }
  132. - (UIButton *)reduce100 {
  133. if (!_reduce100) {
  134. _reduce100 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  135. [_reduce100 setTitle:@"-100" forState:UIControlStateNormal];
  136. _reduce100.frame = CGRectMake(170, 290, 100, 20);
  137. _reduce100.tag = 7;
  138. [_reduce100 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
  139. }
  140. return _reduce100;
  141. }
  142. - (UIButton *)reduce500 {
  143. if (!_reduce500) {
  144. _reduce500 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  145. [_reduce500 setTitle:@"-500" forState:UIControlStateNormal];
  146. _reduce500.frame = CGRectMake(170, 320, 100, 20);
  147. _reduce500.tag = 8;
  148. [_reduce500 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
  149. }
  150. return _reduce500;
  151. }
  152. @end