So how to customize the active area of the button click is actually very simple, just rewrite a function:
-(BOOL) Pointinside: (cgpoint) point withevent: (Uievent *) event
When a touch event occurs, the system detects whether the touch point is in it from the window to the parent control to the child control, and if so, returns Yes, and finally returns the child control of Yes as the control that responds to the event.
We just have to rewrite this method, in which we can judge if we click on the area we want, yes, then return yes, otherwise return no, thus implementing a custom click of the effective region. Note that this side does not change the shape of the button, the button or the rectangle button, just change the button in the response area only.
So the next question is, how do you know if a point is in an area that is not rectangular, this way you can use the Uibezierpath method:
-(BOOL) Containspoint: (cgpoint) point;
We can draw a path based on the desired shape, and then judge by calling the method above to determine it.
For example a square button, how to let him in its circle of the range of a click to react, the other place does not react?
-(BOOL) Pointinside: (cgpoint) point withevent: (Uievent *)Event { //first call the parent class method to determine that the clicked area is indeed in the area of the buttonBOOL res = [Super Pointinside:point withevent:Event]; if(res) {//draw a circular pathUibezierpath *path =[Uibezierpath bezierPathWithOvalInRect:self.bounds]; if([path Containspoint:point]) {//if within the path area, return YesReturnyes; } Returnno; } Returnno;}
This way, clicking on the Circle of the button will have an effect, and no response elsewhere.
IOS Custom button Effective Click Range