Advertisement
Guest User

refactor

a guest
Mar 11th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @implementation ViewController
  2.  
  3. - (void)viewDidLoad {
  4.     [super viewDidLoad];
  5.     // Do any additional setup after loading the view, typically from a nib.
  6.    
  7.     elapsed = 0;
  8.     numOfSpeed = 120;
  9.    
  10.     UIButton *playBtn = [[UIButton alloc] initWithFrame:CGRectMake(200, 200, 50, 50)];
  11.     [playBtn setTitle:@"Play" forState:UIControlStateNormal];
  12.     playBtn.backgroundColor = UIColor.redColor;
  13.     [playBtn addTarget:self action:@selector(playButton:) forControlEvents:UIControlEventTouchUpInside];
  14.     [self.view addSubview:playBtn];
  15.    
  16.     UIButton *incrementBtn = [[UIButton alloc] initWithFrame:CGRectMake(250, 200, 50, 50)];
  17.     [incrementBtn setTitle:@"+" forState:UIControlStateNormal];
  18.     incrementBtn.backgroundColor = UIColor.redColor;
  19.     [incrementBtn addTarget:self action:@selector(incrementButton:) forControlEvents:UIControlEventTouchUpInside];
  20.     [self.view addSubview:incrementBtn];
  21.    
  22.     UIButton *decrementBtn = [[UIButton alloc] initWithFrame:CGRectMake(150, 200, 50, 50)];
  23.     [decrementBtn  setTitle:@"-" forState:UIControlStateNormal];
  24.     decrementBtn.backgroundColor = UIColor.redColor;
  25.     [decrementBtn  addTarget:self action:@selector(decrementButton:) forControlEvents:UIControlEventTouchUpInside];
  26.     [self.view addSubview:decrementBtn ];
  27.    
  28.     self.label = [[UILabel alloc] initWithFrame:CGRectMake(200, 300, 100, 100)];
  29.     self.label.text = [NSString stringWithFormat:@"%.0f", numOfSpeed];
  30.     self.label.backgroundColor = UIColor.blueColor;
  31.     [self.view addSubview:_label];
  32.  
  33.     [self configureSwipeRecognizerWithDirection:UISwipeGestureRecognizerDirectionUp];
  34.     [self configureSwipeRecognizerWithDirection:UISwipeGestureRecognizerDirectionDown];
  35.     [self configureSwipeRecognizerWithDirection:UISwipeGestureRecognizerDirectionLeft];
  36.     [self configureSwipeRecognizerWithDirection:UISwipeGestureRecognizerDirectionRight];
  37.  
  38.    
  39.    
  40. }
  41.  
  42. - (void)configureSwipeRecognizerWithDirection:(UISwipeGestureRecognizerDirection)direction {
  43.     UISwipeGestureRecognizer * recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToControlTheSpeedOfRhythm:)];
  44.     recognizer.direction = direction;
  45.     recognizer.numberOfTouchesRequired = 1;
  46.     [self.view addGestureRecognizer:recognizer];
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement