I want to make a certain section of my UIView clickable. When clicked, it triggers an IBAction, as would an UIButton.
How do I do this?
I want to make a certain section of my UIView clickable. When clicked, it triggers an IBAction, as would an UIButton.
How do I do this?
在您的视图上添加自定义 UIButton,您需要点击的任何位置,然后对其执行操作。
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];
使用 UITapGestureRecognizer 并将透明按钮放在您希望可点击部分可用的区域上
添加UITapGestureRecognizer
到您的UIView
. 当您收到点击时,请检查您的识别器的locationInView:
. 如果点击发生在您想要使点击敏感的区域,则触发操作;否则,忽略点击事件。