How to make a section of my UIView a clickable area

I want to make a specific section of my UIView clickable. Clicking on it launches the IBAction, just like the UIButton.

How should I do it?

+3


source to share


3 answers


Add UITapGestureRecognizer

to yours UIView

. When you receive the tap, check your recognizer locationInView:

. Run the action if a tap has occurred in an area that you want to make sensitive to paint; otherwise, ignore the click event.



0


source


Add a custom UIButton of your opinion, which is always needed for clickability, then take action on it.



    UIButton *button = [UIButton buttonWithType:0];
    [button setFrame:CGRectmake(0,0,0,0)]; //What ever clickable area, provide here
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

      

+3


source


Using a UITapGestureRecognizer and adding a transparent button to the area where you want the accessible section available

+2


source







All Articles