12

I've updated my device to iOS 11 Beta yesterday and my app using this code in AppDelegate for hide back button title on all screen:

@implementation UINavigationItem (Customization)

/**
 Removes text from all default back buttons so only the arrow or custom image shows up.
 */
-(UIBarButtonItem *)backBarButtonItem
{
    return [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
}

It's working normally on older version but when I run my app on iOS 11 Beta, the title of back button still shown. Does anyone face this problem? Is it a beta version bug of iOS or iOS 11 need another way to hide the back button title?

Bad_Developer
  • 537
  • 5
  • 20

4 Answers4

6

I've been using your approach previously, but unfortunately it's not working any more. After trying all possible solutions, that's the only thing that I found working without any issues and bugs. Please note, that it seems that there's no more a universal way to fix this globally for all UIViewControllers.

  1. Call

    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:self.navigationItem.backBarButtonItem.style target:nil action:nil];
    

on viewWillDisappear of the presenting controller.

  1. Call

    self.title = @"Title"
    

on viewWillAppear of the presenting controller.

Other solutions that I have tried have various issues, e.g. they are working fine but everything breaks when you swipe from left edge a bit.

CrazyJoeLv
  • 570
  • 3
  • 6
  • Yeah, I though iOS 11 need a different way to hide back button title. So I was remove my old code then used custom button instead. At this time, it's working without any issues and bugs too. – Bad_Developer Aug 08 '17 at 09:08
  • Thank you for this solution. This is the only solution that works in iOS 11. iOS 11 broke so many things in our app. – coolcool1994 Sep 29 '17 at 01:56
  • Make sure you do this on the viewController it's referring to from the back button, not the one you're segueing into. – Lucas van Dongen Oct 30 '17 at 00:41
2

What I did in iOS 11 was simply to implement the UINavigationControllerDelegate protocol for my root navigation controllers and to set the "blank" UIBarButtonItem as back button everytime a new controller will be displayed. Here is the Swift 4 version:

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
    viewController.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
}
croX
  • 1,725
  • 1
  • 19
  • 23
0

Setting the bar button title text color to clear is the cleanest way I've found to apply for all screens

 UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .normal)
 UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .highlighted)
AFraser
  • 996
  • 4
  • 13
  • 27
0

FOR SWIFT 3+

Use below code to support iOS 9 to 11

     if #available(iOS 11, *) {
            UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .normal)
            UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .highlighted)
     } else {
            UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0,
-60), for:UIBarMetrics.default)
        }
MANISH PATHAK
  • 2,602
  • 4
  • 27
  • 31