2

I created custom navigation buttons like this:

  UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
  [button setImage:[UIImage imageNamed:@"some.png"] forState:UIControlStateNormal];
  ....
  [[current navigationItem] setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:button]];

Where current is UIViewController * type. All works fine and button created, but it's clickable area outside the button, very close to the middle of the navigation bar. Is it possible to limit clickable area?

ArisRS
  • 1,362
  • 2
  • 19
  • 41
  • your question familiar with [this topic](http://stackoverflow.com/questions/9338681/issue-with-button-on-the-left-side-of-the-uinavigation-bar). Apple made it this way for ease of use – dementiazz Sep 27 '12 at 10:21

3 Answers3

5

I believe thats a "feature" of iOS. THe Navigation Buttons on left and right are smaller than the minimum touch area allowed in iOS. As a result the actual hit zone is much larger than the physical NavigationButton. Including just under the bar, and like you're noticing to the left and right of the button. Its to allow quick touches without having "look" where you're touching. Its one of the key reasons iPhones are more natural to use than most android phones in the early days.

Ryan Poolos
  • 18,421
  • 4
  • 65
  • 98
0

My best guess is that the button is set to center the image and not scale it, so the frame of the button is way too big.

button.frame=CGRectMake(x,y,w,h)

Set the frame to what you want the clickable area to be.

flagoworld
  • 3,196
  • 2
  • 20
  • 16
0

I have initially thought about subclassing the UIBarButtonItem and override -touchInside:.

This does not work though, since UIBarButtonItem is not a subclass of UIView.
What you are trying to achieve is therefore not possible without overriding some private API.

Christian Schnorr
  • 10,768
  • 8
  • 48
  • 83