سؤال

I've created a custom button as an NavigationItem at the rightBarBuuttonItem. It works well, but when I click outside the button, for example a little down of the button, it still works. Here is my code

fetchButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[fetchButton setImage:[UIImage imageNamed:@"quanse.png"] forState:UIControlStateNormal];
[fetchButton addTarget:self action:@selector(searchDataByColor) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc] initWithCustomView:fetchButton]; 

Anybody who can tell me, what can I do to fix this bug?

هل كانت مفيدة؟

المحلول

What you are describing is actually the normal behavior of the UIButton. The actual touchable area extends beyond the visible borders of the button. You can see this behavior in Apple's own apps.

Normally this is a convenience for the user, but if you find it undesirable in your app, there's a possible workaround solution in this prior question:

UINavigationItem Back Button touch area too large

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top