UIBarButtonItem-Badge icon indicating copy to clipboard operation
UIBarButtonItem-Badge copied to clipboard

Tapping on buttons with the badges sometime do not work

Open maxykato opened this issue 9 years ago • 3 comments

I implemented this library in my Swift project, and it works great. I really appreciate it.

The only problem I have is that tapping on the buttons with the badges sometime fails. I assume that it might be because badges do not accept touch gestures and the size of touchable area on the buttons becomes smaller.

Is possible to fix it? Or is there any workaround?

maxykato avatar Dec 20 '15 07:12 maxykato

Looking forward to any reply...

maxykato avatar Feb 08 '16 15:02 maxykato

I have the same problem. Did you find a solution, @maxykato ?

halset avatar Jan 17 '18 20:01 halset

The badge is implemented as a UILabel on top of the UIButton preventing it to receive the touch events. I managed to address the issue by adding a gesture recognizer on the badge itself.

    UIImage *image = [UIImage imageNamed:@"navbarIconShareSelected"];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0,0,image.size.width, image.size.height);
    [button addTarget:self action:@selector(shareButtonPressed) forControlEvents:UIControlEventTouchDown];
    [button setBackgroundImage:image forState:UIControlStateNormal];
    
    UIBarButtonItem *navRightButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = navRightButton;

    // The badge on the uibarbutton is a UILabel that prevent taps to trigger the shareButtonPressed event. Add a gesture recognizer to capture tap events
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self
                                            action:@selector(shareButtonPressed)];
    [navRightButton.badge addGestureRecognizer:tapGesture];
    

Guruniverse avatar Mar 12 '18 00:03 Guruniverse