简体   繁体   English

NavigationBar BackButton的文本,如果NavigationBar的标题太长

[英]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. 我有一个自定义文本作为后退按钮,但自iOS7以来它自动缩短为默认的“后退”文本,甚至根本不删除。 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: 您可以在要导航回的视图控制器的viewDidLoad方法中设置自定义后退按钮:

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() 例如,在viewDidLoad()

In swift: 在快速:

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

In Objective-c: 在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. 重要提示 :你必须要做到这一点, 从该 SEGUE启动控制器。

For example, if the segue goes from ViewController1 to ViewController2 , you would have to write the previous code in the viewDidLoad() implementation of ViewController1 例如,如果segue从ViewController1转到ViewController2 ,则必须在ViewController1viewDidLoad()实现中编写前面的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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