Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBarButtonItem has a too large click area

I know some have already asked the question but so far, the answers are not really specific.

Apparently apple have made the click area of the NavigationBar larger than it really is, but I don't think it's supposed to be that large.

In my app, there is a TableView right underneath the NavBar and you can click all the way down to half of the first cell to trigger the event of the rightBarButtonItem. the button is instanced like this:

    UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editTable)];
 [[self navigationItem] setRightBarButtonItem:editButton];

"self" is the root ViewController of a NavigationController.

As you could imagine, it's a problem since the cells are selectable to push another ViewController.

I managed to go around the problem by making the cells' height bigger but I'd rather have them at the regular size.

I'm sure I'm not the only one with this case of scenario. Thanks in advance.

like image 691
DEIONaLiMs Avatar asked Feb 27 '23 14:02

DEIONaLiMs


1 Answers

UIButton *menuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[menuButton addTarget:self action:@selector(revealMenu:) forControlEvents:UIControlEventTouchUpInside];
[menuButton setImage:[UIImage imageNamed:@"menuIcon"] forState:UIControlStateNormal];
UIView *menuButtonContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[menuButtonContainer addSubview:menuButton];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:menuButtonContainer];

This perfectly worked for me....

like image 63
iosDeveloper Avatar answered Mar 07 '23 09:03

iosDeveloper