How to change text on a back button

前端 未结 20 1974
无人及你
无人及你 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:58

    //You can achieve this by setting the title in the previous view controller as shown below

    override func viewWillAppear(animated: Bool) {
            super.viewWillAppear(animated)
            //Set Title for this view
            self.navigationItem.title = "My Title"
    
    }
    
    override func viewWillDisappear(animated: Bool) {
            super.viewWillAppear(animated)
            //Set Title for back button in next view 
            self.navigationItem.title = "Back"
    }
    
    0 讨论(0)
  • 2020-11-29 18:00

    For to change back button title, refer below code

    InformationVC *infoController=[[InformationVC alloc]init];[self.navigationController infoController animated:YES];
    
    //Below code changed back button title on InformationVC page.
    UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Information" style: UIBarButtonItemStylePlain target: nil action: nil];
    self.navigationItem.backBarButtonItem = backBarButton;`enter code here`
    
    0 讨论(0)
提交回复
热议问题