3

I have a NavigationController based iOS7 app , on this I want to hide the back button text which is displayed along with the chevron. Is there a way out to this ? I tried setting empty string to the back button title , tried empty title on previous view as well seems like if it finds empty title it replaces that with "Back" text.

Please help

Thanks

fractious
  • 1,642
  • 16
  • 30
vishal dharankar
  • 7,536
  • 7
  • 57
  • 93
  • Do you just want to see the chevron/back arrow without any text or do you want to hide the back button completely? The former is a bad idea (IMHO, unless you need the additional space), the later has been answered multiple times already here on StackOverflow. – DarkDust Jan 22 '14 at 09:48
  • @DarkDust yes i need more space due to some reason. – vishal dharankar Jan 22 '14 at 10:10
  • So you've tried using `@""` (`nil` won't work, that will give you "Back")? What about `@" "` (a single space)? – DarkDust Jan 22 '14 at 10:17
  • Yes tried spaces not working – vishal dharankar Jan 22 '14 at 13:51
  • 1
    possible duplicate of [iOS 7 navigation bar custom back button without title](http://stackoverflow.com/questions/18870128/ios-7-navigation-bar-custom-back-button-without-title) – DarkDust Jan 22 '14 at 15:03
  • 1
    Also, this might be of interest: http://stackoverflow.com/questions/18912638/custom-image-for-uinavigation-back-button-in-ios-7 – DarkDust Jan 22 '14 at 15:05
  • @DarkDust first link has some answers they helped, but not all of them work lol – vishal dharankar Jan 22 '14 at 18:28
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/45905/discussion-between-vishal-and-darkdust) – vishal dharankar Jan 23 '14 at 11:34

5 Answers5

11

Finally ended up solving it as follows , this one worked perfect.

self.navigationController.navigationBar.topItem.title = @"";

from this link Removing the title text of an iOS UIBarButtonItem

But if you navigate from previous view to next view you can see that the title of the previous view navigation bar vanishes when i put the above mentioned solution in viewDidDisappear of viewWillDisappear of previous view, which isn't an elegant solution in storyboard based UINavigationController scenario , in another situation i finally decided to use a bar button and set its image as per the native back button chevron, this gives better results.

Community
  • 1
  • 1
vishal dharankar
  • 7,536
  • 7
  • 57
  • 93
  • I posted a different answer below to address the drawback you mentioned about the title vanishing... – Erwan Jan 13 '15 at 08:22
9

The answer proposed by @vishal has a serious drawback: it removes the title from controller A if you navigate back from A to B.

Here is a safer solution to apply on controller A before pushing controller B:

self.navigationController.navigationBar.topItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];

And for swift:

if let topItem = controller.navigationController?.navigationBar.topItem {
    topItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
}
Mathijs Segers
  • 6,168
  • 9
  • 51
  • 75
Erwan
  • 3,733
  • 30
  • 25
3

If you want to hide back button title into all your app, put this in you App Delegate:

@implementation UINavigationItem (myCustomization)

-(UIBarButtonItem *)backBarButtonItem
{
    return [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
}

@end

tested on iOS 7

Luca Iaco
  • 3,387
  • 1
  • 19
  • 20
  • This is awesome. Works like a charm to make sure that ALL back buttons in the app have just the arrow and no text. – teradyl Mar 21 '16 at 21:02
1

For hide the back button of navigation controller ,try this one:

[self.navigationItem setHidesBackButton:YES animated:YES];
[self.navigationItem setBackBarButtonItem:nil];
[self.navigationItem setLeftBarButtonItem:nil animated:NO];

may it will help you.

happy coding...:)

Dhaval Bhadania
  • 3,090
  • 1
  • 20
  • 35
0

The simplest solution is to remove the back button title with

navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)

in viewWillAppear on the presenting view controller. Note, presenting not presented.

From Removing the title text of an iOS UIBarButtonItem.

Community
  • 1
  • 1