UIBarButtonItem-Badge
UIBarButtonItem-Badge copied to clipboard
Tapping on buttons with the badges sometime do not work
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?
Looking forward to any reply...
I have the same problem. Did you find a solution, @maxykato ?
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];