0

I am trying to set my backButton to a simple "<" like this:

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

The printing will display "", but running my app on the simulator will always display the title of the previous VC.

Though I tested

 navigationController?.navigationBar.tintColor = UIColor(red:0.60, green:0.60, blue:0.60, alpha:1.0)

will change the button's color.

Note:

I am pushing from a UIViewController embedded in a UINavigationController to just a UIViewController

Kirit Modi
  • 23,155
  • 15
  • 89
  • 112
JVS
  • 2,592
  • 3
  • 19
  • 31

4 Answers4

1

You need to hide the backbarbutton title through out your app,right?

  • Then this trick may help you in achieving that.

    Swift:

    UIBarButtonItem.appearance().setTitlePositionAdjustment(UIOffsetMake(0, -100), forBarMetrics: UIBarMetrics.Default)
    

    Objective C:

    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -100)
                                                     forBarMetrics:UIBarMetricsDefault];
    

Add the above code in your appdelegate didFinishLaunchingWithOptions,we are pushing the title out of the frame(hidden) :p.

Result:

enter image description here

Gokul G
  • 2,046
  • 15
  • 22
0
self.navigationItem.backBarButtonItem = UIBarButtonItem(title:"<", style:.Plain, target:nil, action:nil)
Sofeda
  • 1,361
  • 1
  • 13
  • 23
0

In objective c use following code in pushing controller:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"   " style:UIBarButtonItemStylePlain target:nil action:nil];                                                     
[self.navigationItem setBackBarButtonItem:backButton];
self.navigationController.navigationBar.backIndicatorImage = [UIImage imageNamed:ARROW_BACK_ICON];

Do not use "" title for back button use " " title for back button.

Kirit Modi
  • 23,155
  • 15
  • 89
  • 112
0

Try this

Select your Main.storyboard -> Click Hide Document Outline-> Choose your UIViewController-> Select Navigation Item -> Select Show the attributes inspector-> Back button textfield with one space Back button = " "

OR

EDITED

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

hope this helps.

Kamlesh Shingarakhiya
  • 2,757
  • 2
  • 16
  • 34