Search code examples
objective-cuiviewios6uiimageviewuilabel

How to make UIView clickable


I have a custom UIView that contains a UILabel and a UIImageView. How do I make my UIView clickable? I want the background of the UIView to change any time a user starts to press down on the UIView. The color should change back when the user lifts up on the button. I also need to be able to handle the click event.


Solution

  • -(void)addGestureRecogniser:(UIView *)touchView{
    
        UITapGestureRecognizer *singleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changecolor)];
        [touchView addGestureRecognizer:singleTap];
        DBLog(@"ADD GESTURE RECOGNIZER");
    }
    -(void)changecolor{
    
      // do something
    
    
    }
    

    1`) this is code snippet where in u need to pass the view as a parameter so as to make it clickable.