0

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?

Community
  • 1
  • 1
Khant Thu Linn
  • 5,905
  • 7
  • 52
  • 120

3 Answers3

5

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.

Atif Alvi
  • 498
  • 4
  • 12
2

One solution you will have to add custom button for your requirement like this:

//create image instance add here back image
UIImage *imgBack = [UIImage imageNamed:@"image name here"];

//create UIButton instance for UIBarButtonItem
UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
[btnBack setImage:imgBack forState:UIControlStateNormal];
btnBack.frame = CGRectMake(0, 0, imgBack.size.width,imgBack.size.height);
[btnBack addTarget:self action:@selector(btnBackAction:) forControlEvents:UIControlEventTouchUpInside];

//create UIBarButtonItem instance
UIBarButtonItem *barBtnBackItem = [[UIBarButtonItem alloc] initWithCustomView:btnBack];
//set in UINavigationItem
self.navigationItem.leftBarButtonItem = barBtnBackItem;

Button method given below:

-(void)btnBackAction:(id)sender
{
   [self.navigationController popViewControllerAnimated:YES];
}

EDIT : For slide swipe add in viewDidLoad method

//for enabling swipe gesture
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
2

@Atif's answer is correct. I just want to add in that, instead of copying and pasting the code in all files, create a custom UINavigationController and implement the required code as mentioned by @Atif.(I cannot comment due to low rating.)

Adnan Asghar
  • 341
  • 1
  • 3
  • 13