UIButton not allocated on border

I create a UIButton programmatically using the following code:

myButton = [UIButton new];
[myButton setImage:[UIImage imageNamed:@"myButtonNormal"]
                              forState:UIControlStateNormal];
[myButton setBackgroundImage:[UIImage imageNamed:@"myButtonBackgroundNormal"]
                                        forState:UIControlStateNormal];
myButton.alpha = MY_BUTTON_ALPHA;

[myButton addTarget:self
             action:@selector(myButtonSelector:)
   forControlEvents:UIControlEventTouchUpInside];

[self.parentViewController.view insertSubview:myButton 
                                      atIndex:10];

Now the problem is with the backlight of the button when it is pressed. It works well, i.e. The color of the button changes when pressed, except when I click on the very border of the left side of the button. To illustrate this:

enter image description here

When the green part of the button is pressed, everything is in order, and the button is highlighted. When the red part is pressed, the button for selecting the button is called, that is, the button works, but the backlight does not work.

I tested this on a simulator to be able to make more accurate clicks.

, , . , , , , UIGestureRecognizerDelegate.

, ?

+4
2

, , UIScreenEdgePanGestureRecognizer, . , UIScreenEdgePanGestureRecognizer. , UIViewController:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([touch.view isKindOfClass:[UIButton class]])
    {
        return NO;
    }
    return YES;
}
+2

, . -

[myButton addTarget:self action:@selector(highlightButtonBorder:) forControlEvents:UIControlEventTouchDown];

- (void)highlightButtonBorder:(id)sender
{
    myButton.layer.borderColor = [[UIColor redColor]CGColor];
}

-

 #import <QuartzCore/QuartzCore.h>
0

Source: https://habr.com/ru/post/1588972/


All Articles