iosuinavigationbartitleview

Can't set titleView in Navigation bar center and scope of back button increased


I am trying to push a view controller and set its navigation bar's title but it is not centered due to long title being used i guess. Along with that, scope of the back button is increased till the title view, i.e if I tap with with Milestone's "M", it gets back though it frame is the same.

enter image description here

Bounds of back button are the same but its click impact is elongated.

enter image description here

Below is the code for how I am pushing the view controller.

 MilestoneDetailsViewController *controller = [[MilestoneDetailsViewController alloc] initWithNibName:@"MilestoneDetailsViewController" bundle:nil];
    [self.navigationController pushViewController:controller animated:YES];

and in the MilestoneDetailsViewController, i set the title as following:

self.title = NSLocalizedString(@"Milestone Details", nil);

Solution

  • Back button is picking its size according to the title of previous viewController. you can change it to a empty String for example, in your previous viewController from where you are pushing write this code.

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