Pathetic Learner
Pathetic Learner

Reputation: 729

Action on UILabel in iphone

I have created some set of labels programmatically to display on the screen and i want after clicking on label some action should perform.

Please don't suggest me about UIButton. I want to do it for UILabel. After clicking on the label another detail view should appear.

Please help me to solve this problem without using Inteface Builder.

Upvotes: 9

Views: 9791

Answers (3)

Pathetic Learner
Pathetic Learner

Reputation: 729

Finally i came up with the solution and i got the result

 [titleLbl setUserInteractionEnabled:YES];
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelButton:)];
    [tapGestureRecognizer setNumberOfTapsRequired:1];
    [titleLbl addGestureRecognizer:tapGestureRecognizer];
    [tapGestureRecognizer release];

Upvotes: 23

Muhammed Ayaz
Muhammed Ayaz

Reputation: 1398

In

  -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
 .......
 .......
 CGPoint touch;//Touch Location

if(CGRectContainsPoint([objectOfLable frame], [touch locationInView:self.view ]) )
{
  Do What you Want
}

}

Try This

Upvotes: 3

Saurabh Passolia
Saurabh Passolia

Reputation: 8109

make IBoutlet of your label, implement touchesBegin in your controller, pull out the CGPoint - touchCoordinate, check

CGRectContainsPoint(label.frame,touchCoordinate)
{
//you got the touch action on your label
}

Upvotes: 4

Related Questions