简体   繁体   中英

NavigationBar BackButton's text if NavigationBar's title is too long

I have a custom text as Back button but since iOS7 it's automatically shortened to default "Back" text or even removed at all. Is there any way to change that default "Back" text to something else? I would rather have it removed at all than replaced with "Back" text.

做到这一点

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

You can set a custom back button in the viewDidLoad method of the view controller that you want to navigate back to:

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

Yes, you can do that. For example, in viewDidLoad()

In swift:

self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "Custom Title", style: .Plain, target: nil, action: nil)

In Objective-c:

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

You can also set the title to "" if you want to delete the title and to only show the < symbol.

Important : you have to do this in the controller from which the segue starts.

For example, if the segue goes from ViewController1 to ViewController2 , you would have to write the previous code in the viewDidLoad() implementation of ViewController1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM