123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- //
- // ViewController.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/1/14.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "ViewController.h"
- #import "SVGA.h"
- #import <SDWebImage/SDImageCache.h>
- #import "XYScrollNumberLabel.h"
- @interface ViewController ()
- @property (nonatomic, strong) XYScrollNumberLabel *scrollLabel;
- @property (nonatomic, strong)UIButton *addOne;
- @property (nonatomic, strong)UIButton *addFive;
- @property (nonatomic, strong)UIButton *add100;
- @property (nonatomic, strong)UIButton *add500;
- @property (nonatomic, strong)UIButton *reduceOne;
- @property (nonatomic, strong)UIButton *reduceFive;
- @property (nonatomic, strong)UIButton *reduce100;
- @property (nonatomic, strong)UIButton *reduce500;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- self.scrollLabel = [[XYScrollNumberLabel alloc] initImageNumberLabelWithNeewMark:YES imageSize:CGSizeMake(20.0f, 28.0f)];
- self.scrollLabel.frame = CGRectMake(100, 100, self.scrollLabel.frame.size.width, self.scrollLabel.frame.size.height);
- [self.view addSubview:self.scrollLabel];
-
- [self.view addSubview:self.addOne];
- [self.view addSubview:self.reduceOne];
- [self.view addSubview:self.addFive];
- [self.view addSubview:self.reduceFive];
- [self.view addSubview:self.add100];
- [self.view addSubview:self.reduce100];
- [self.view addSubview:self.add500];
- [self.view addSubview:self.reduce500];
- }
- - (void)buttonClicked:(UIButton *)sender {
-
- NSInteger tmp = self.scrollLabel.displayedNumber;
-
- switch (sender.tag) {
- case 0:
-
- break;
- case 1:
- [self.scrollLabel changeToTargetNumber:tmp + 1 duration:0.5 animated:YES];
- break;
- case 2:
- [self.scrollLabel changeToTargetNumber:tmp + 5 duration:0.5 animated:YES];
- break;
- case 3:
- [self.scrollLabel changeToTargetNumber:tmp + 100 duration:0.5 animated:YES];
- break;
- case 4:
- [self.scrollLabel changeToTargetNumber:tmp + 500 duration:0.5 animated:YES];
- break;
- case 5:
- [self.scrollLabel changeToTargetNumber:tmp - 1 animated:YES];
- break;
- case 6:
- [self.scrollLabel changeToTargetNumber:tmp - 5 animated:YES];
- break;
- case 7:
- [self.scrollLabel changeToTargetNumber:tmp - 100 animated:YES];
- break;
- case 8:
- [self.scrollLabel changeToTargetNumber:tmp - 500 animated:YES];
- break;
- default:
- break;
- }
- }
- - (UIButton *)addOne {
- if (!_addOne) {
- _addOne = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- [_addOne setTitle:@"+1" forState:UIControlStateNormal];
- _addOne.frame = CGRectMake(70, 230, 100, 20);
- _addOne.tag = 1;
- [_addOne addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _addOne;
- }
- - (UIButton *)addFive {
- if (!_addFive) {
- _addFive = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- [_addFive setTitle:@"+5" forState:UIControlStateNormal];
- _addFive.frame = CGRectMake(70, 260, 100, 20);
- _addFive.tag = 2;
- [_addFive addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _addFive;
- }
- - (UIButton *)add100 {
- if (!_add100) {
- _add100 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- [_add100 setTitle:@"+100" forState:UIControlStateNormal];
- _add100.frame = CGRectMake(70, 290, 100, 20);
- _add100.tag = 3;
- [_add100 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _add100;
- }
- - (UIButton *)add500 {
- if (!_add500) {
- _add500 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- [_add500 setTitle:@"+500" forState:UIControlStateNormal];
- _add500.frame = CGRectMake(70, 320, 100, 20);
- _add500.tag = 4;
- [_add500 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _add500;
- }
- - (UIButton *)reduceOne {
- if (!_reduceOne) {
- _reduceOne = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- [_reduceOne setTitle:@"-1" forState:UIControlStateNormal];
- _reduceOne.frame = CGRectMake(170, 230, 100, 20);
- _reduceOne.tag = 5;
- [_reduceOne addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _reduceOne;
- }
- - (UIButton *)reduceFive {
- if (!_reduceFive) {
- _reduceFive = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- [_reduceFive setTitle:@"-5" forState:UIControlStateNormal];
- _reduceFive.frame = CGRectMake(170, 260, 100, 20);
- _reduceFive.tag = 6;
- [_reduceFive addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _reduceFive;
- }
- - (UIButton *)reduce100 {
- if (!_reduce100) {
- _reduce100 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- [_reduce100 setTitle:@"-100" forState:UIControlStateNormal];
- _reduce100.frame = CGRectMake(170, 290, 100, 20);
- _reduce100.tag = 7;
- [_reduce100 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _reduce100;
- }
- - (UIButton *)reduce500 {
- if (!_reduce500) {
- _reduce500 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- [_reduce500 setTitle:@"-500" forState:UIControlStateNormal];
- _reduce500.frame = CGRectMake(170, 320, 100, 20);
- _reduce500.tag = 8;
- [_reduce500 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _reduce500;
- }
- @end
|