How to change text on a back button

前端 未结 20 1970
无人及你
无人及你 2020-11-29 17:24

By default the back button uses as a text on it a title of a viewcontroller. Can I change text on the back button without changing a title of a view controller? I need this

相关标签:
20条回答
  • 2020-11-29 17:56

    Try

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

    I found that by looking at the backBarButtonItem docs in Apple's docs for UINavigationItem.

    0 讨论(0)
  • 2020-11-29 17:56

    Marc W's approach worked great once I figured out which controller to apply it to: the one being re-titled, not the one on top. So if this is the navigation stack:

    (bottom)  ControllerA -> ControllerB  (top)
    

    ...and you want to give a shorter title for ControllerA in the back-button displayed when ControllerB is on top, you apply the property change to ControllerA.

    So it's more in the context of self.title, not like the other left/right-bar-button setters.

    0 讨论(0)
  • 2020-11-29 17:56

    If you are using storyboard:

    1. Open StoryBoard
    2. In Document Outline window find ViewController to which you want to return to
    3. Click on Navigation Item of that ViewController
    4. In Attributes explorer change Back Button value to your custom tile

    That is it, enjoy...

    0 讨论(0)
  • 2020-11-29 17:56
    [self.navigationItem setBackBarButtonItem:[[UIBarButtonItem alloc]
      initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil]];
    

    This worked for me.

    0 讨论(0)
  • 2020-11-29 17:57

    [self.navigationController.navigationBar.backItem setTitle:@"back"];

    It works for me. You can replace "back" with something else.

    0 讨论(0)
  • 2020-11-29 17:58

    This one worked for me if you don't want to have a title!

    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStylePlain target:nil action:nil];
    
    0 讨论(0)
提交回复
热议问题