Akshara
Akshara

Reputation: 141

How to hide only the back bar button item title in iOS objective c

I know to hide the back bar button item. But I want to hide only the title of the bar button i.e. the back button is like this: "< Back". I want only the arrow not the name i.e. "<". How do I remove the "Back" and retain only the back arrow.

Thanks,

Upvotes: 3

Views: 1212

Answers (5)

S.M.Moinuddin
S.M.Moinuddin

Reputation: 333

*Swift 3.1 You can do this by implementing the delegate method of UINavigationController. It'll hide the Title with back button only, we'll still get the back arrow image and default functionality.

func navigationController(_ navigationController: UINavigationController, 
  willShow viewController: UIViewController, animated: Bool) {
        let barBttn = UIBarButtonItem(title: " ", style: .plain, target: nil, 
                    action: nil)
        viewController.navigationItem.backBarButtonItem = barBttn
    }

Upvotes: 0

S.M.Moinuddin
S.M.Moinuddin

Reputation: 333

You can do this by implementing the delegate method of UINavigationController.

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) { let item = UIBarButtonItem(title: " ", style: .plain, target: nil, action: nil) viewController.navigationItem.backBarButtonItem = item }

Upvotes: 0

Maulik Patel
Maulik Patel

Reputation: 397

It's Easy

(1) Create LeftbarButton item

UIImage *imgBackArrow = [UIImage imageNamed:@"back_arrow"];
UIBarButtonItem *barBackButton = [[UIBarButtonItem alloc] initWithImage:imgBackArrow style:UIBarButtonItemStylePlain target:self action:@selector(backButtonClicked)];
self.navigationItem.leftBarButtonItem = barBackButton;

(2) Hide Xcode back Button

[self.navigationItem setHidesBackButton:YES];

Upvotes: 1

Irfan
Irfan

Reputation: 4331

You can achieved this easily from storyboard, go to your specific view of storyboard for whom you want to show blank back button title with arrow.

Then make sure you added navigation item in your specific view:

enter image description here

Then on the right panel you can find:

enter image description here

You just need to give some empty space in the back button box:

enter image description here

And you are done. Hope it will help you thanks.

Upvotes: 3

Ashish Ramani
Ashish Ramani

Reputation: 1214

This may help you....

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

Upvotes: 1

Related Questions