title: Getting tag of UILabel on click
body: <p>I am dynamically creating UILabels and then saving their tag in an NSMutableArray. I then have a method that detects taps (clicks) on these UILabels. Basically when a UILabel that has been dynamically generated is clicked I want to have it deleted without deleting other labels. However, in future I may want to do more then just delete. But at the moment I feel like I am stuck at a dead end trying to find a way to do this. Any ideas?</p>
  
  <p>Heres my code:</p>
  
  <pre><code>- (void)viewDidLoad
  {
  [super viewDidLoad];
  // Do any additional setup after loading the view, typically from a nib.
  // set corner radius
  coverview.hidden=YES;
  labeltextfield.hidden=YES;
  textcreate.hidden=YES;
  
  
  labeltags = [NSMutableArray  array];
  labeltext = [NSMutableArray array];
  
  }
  
  -(IBAction)removeboard
  {
  [labeltextfield resignFirstResponder];
  }
  
  -(void)showtextcreator {
  // Create bg cover
  coverview.hidden=NO;
  labeltextfield.hidden=NO;
  textcreate.hidden=NO;
  
  //Make sure creating screen is always on top
  [self.view bringSubviewToFront:coverview];
  [self.view bringSubviewToFront:labeltextfield];
  [self.view bringSubviewToFront:textcreate];
  
  }
  
  -(void)createtext {    
  NSInteger obj = [labeltags count] +1 ;
  [labeltags addObject:[NSNumber numberWithInteger:0]];
  
  int posx = arc4random() % 300 ;
  int posy = arc4random() % 400 ;
  int frame = arc4random() % 400 ;
  
  NSString *txt = labeltextfield.text;
  //  NSString *framename = (@"frame%i",frame);
  
  [labeltext addObject:txt];
  
  [labeltags addObject:[NSNumber numberWithInteger:0]];
  
  CGRect labelframe = CGRectMake( posx, posy, 100, 30);
   label = [[UILabel alloc] initWithFrame: labelframe];
  [label setText: [NSString stringWithFormat:@"%@", txt]];
  [label setTextColor: [UIColor orangeColor]];
  label.backgroundColor = [UIColor clearColor];
  label.tag=obj;
  [self.view addSubview: label];
  
  label.userInteractionEnabled = YES;
  
  UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc]
                                      initWithTarget:self
                                      action:@selector(labelDragged:)];
  [label addGestureRecognizer:gesture];
  
  UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
  
  [label addGestureRecognizer:recognizer];
  
  
  
  coverview.hidden=YES;
  labeltextfield.hidden=YES;
  textcreate.hidden=YES;
  
  
  }
  
  - (void)labelDragged:(UIPanGestureRecognizer *)gesture
  {
  label = (UILabel *)gesture.view;
  CGPoint translation = [gesture translationInView:label];
  
  // move label
  label.center = CGPointMake(label.center.x + translation.x,
                             label.center.y + translation.y);
  
  // reset translation
  [gesture setTranslation:CGPointZero inView:label];
  }
  
  
  - (void)tapAction {
      UILabel *labelnew = (UILabel *)[self.view viewWithTag:1];
      NSLog(@"Text is %@",labelnew.text);
  }
  </code></pre>