Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action on UILabel in iphone

Tags:

ios

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.

like image 704
Pathetic Learner Avatar asked Dec 23 '11 11:12

Pathetic Learner


3 Answers

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];
like image 170
Pathetic Learner Avatar answered Oct 06 '22 09:10

Pathetic Learner


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
}
like image 35
Saurabh Passolia Avatar answered Oct 06 '22 11:10

Saurabh Passolia


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

like image 26
Ayaz Avatar answered Oct 06 '22 09:10

Ayaz