Nikunj Jadav
Nikunj Jadav

Reputation: 3402

iPhone:Can't tap UILabel at specified frame using UITapGestureRecognizer

I am used UITapGestureRecognizer in my apps but I can't to tap on the UILabel only so please help to solve this problem and I want to redirect on next view controller click on e letter of UILabel so please help me .......

  self.label = [[UILabel alloc] initWithFrame:CGRectMake(45, 48, 94, 21)];
  self.label.backgroundColor = [UIColor clearColor];
  self.label.text = @"I like iPhone";

recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
  [self.label addGestureRecognizer:recognizer];
  [self.view addSubview:label];
   self.tapRecognizer = (UITapGestureRecognizer *)recognizer;
   recognizer.delegate = self;
   [recognizer release];    

Thanks in advance.

Upvotes: 1

Views: 459

Answers (2)

Feanor
Feanor

Reputation: 670

You have to enable user interaction for a label, it is disabled by default.

self.label.userInteractionEnabled = YES;

Upvotes: 0

Vladimir
Vladimir

Reputation: 170829

UILabel by default does not allow user interaction - you must explicitly enable it:

self.label.userInteractionEnabled = YES;

Upvotes: 1

Related Questions