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?
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)
}
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.
Call
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:self.navigationItem.backBarButtonItem.style target:nil action:nil];
on viewWillDisappear
of the presenting controller.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With