Search code examples
iosuinavigationcontrolleruinavigationitem

ios hide text of left navigation button


I need to show only arrow button and hide text of left navigation button. According to this link, I can do like this. But if I do like that, slide to go back feature will be destroyed.

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

So, I use like this to hide text.

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

So far, it is okay. However, if my previous view's searchDisplayController is active and push to new view,it show left navigation button text. May I know how to do?


Solution

  • Copy and paste this line in every view controller:

    self.navigationController.navigationItem.leftBarButtonItem.title = " "
    

    Alternatively you can achieve this in storyboard/xib files using the following steps:-

    1. Drag and drop a Navigation Item from object library onto your ViewController. Then select the ViewController.
    2. Select that Navigation Item in the menu on left side(it will the one with back arrow and Title as text: "< Title").
    3. Select Attribute Inspector on the right hand side and replace text: Title with an empty space.

    Repeat these steps for all the the view controllers. Hope it helps.