0

I am trying to create a custom back button on a navigation bar. I start from the following:

// Nav bar - back button
[[UINavigationBar appearance] setTintColor:COLOR_WHITE];
[[UINavigationBar appearance] setBackIndicatorImage:[[UIImage imageNamed:@"navMenuBackButton"]
                                                     imageWithAlignmentRectInsets:UIEdgeInsetsMake(6.0, -6.0, 6.0, -6.0)]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"navMenuBackButton"]];

The image is 34x34 points so does not centre properly without the image alignment. The current problem is trying to get rid of the "Back" label without setting a blank title for each screen or making any changes on the ViewController itself.

Any idea's? Thank you

rjinski
  • 615
  • 1
  • 7
  • 12
  • 1
    Thinking out loud really: How about subclassing UINavigationBar then using `UINavigationController - (instancetype)initWithNavigationBarClass:(Class)navigationBarClass toolbarClass:(Class)toolbarClass` – Mike Pollard Jan 29 '14 at 14:58

2 Answers2

1

Disable leftBarButtonItem and rightBarButtonItem. Try the following.

[navigationItem.backItem.leftBarButtonItem setEnabled:NO];
[navigationItem.backItem.rightBarButtonItem setEnabled:NO];
[navigationItem.backItem setHidesBackButton:YES];
GMJigar
  • 496
  • 4
  • 14
0

Did you try this :

NSString *backString = @"";
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:backString 
                                                               style:UIBarButtonItemStyleDone 
                                                              target:nil 
                                                              action:nil];
[[self navigationItem] setBackBarButtonItem:backButton];
valverij
  • 4,871
  • 1
  • 22
  • 35
zerbfra
  • 190
  • 12
  • Yes. It works the same as `self.navigationItem.title = @"";` But this needs to be called for each View Controller which I want to try and avoid – rjinski Jan 29 '14 at 14:47