3

我一直遇到一个问题,当我将项目推到导航控制器上时,后退按钮只会说“后退”。我尝试设置断点并检查堆栈上的导航项。堆栈上的所有项目都有一个 nil backButtonItem 和一个标题。我什至尝试设置 backBarButtonItem 但仍然只是说“返回”。还有其他人有这个问题吗?

4

4 回答 4

8

iOS 7 will automatically replace your back button title with "Back" or even remove the title altogether in order to fit the title of current navigation item. You probably shouldn't try to do anything about it except maybe try and make your titles shorter.

于 2013-09-23T18:47:11.453 回答
0

在 iOS 7 中,前一个控制器导航项的标题属性更改了下一个控制器中的后退按钮。基本上,后退按钮标题是前一页的标题。

但是,如果您希望后退按钮的标题与前一个控制器的标题不同,最好的选择是将该控制器的导航项标题视图设置为UILabel. 然后,您可以将该控制器的导航项标题属性设置为后退按钮应显示的任何内容。创建具有正确字体和大小的标签的示例代码:

NSString * title = @"Title of page";
NSDictionary * titleAttribs = navigationController.navigationBar.titleTextAttributes;
UILabel * titleLabel = [[UILabel alloc] init];
NSAttributedString * titleAttrString = [[NSAttributedString alloc] initWithString:title attributes:titleAttribs];

// the attributed text misses the bold attribute (because bold is not considered as font attribute in Cocoa)
titleLabel.attributedText = titleAttrString;

// get font and make it bold
UIFont * font = titleLabel.font;
UIFontDescriptor * fontDesc = [font.fontDescriptor
                               fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];
UIFont * boldFont = [UIFont fontWithDescriptor:fontDesc size:0]; // size:0 means keep the size as is
titleLabel.font = boldFont;
[titleLabel sizeToFit];


anotherController.navigationItem.titleView = titleLabel; // this will be the title in NavBar
anotherController.navigationItem.title = @"Go back"; // this will be the title of the back button

[navigationController pushViewController:anotherController animated:YES];
于 2014-02-14T18:34:56.557 回答
0
self.navigationController.navigationBar.backItem.title = @"Back!";
于 2014-06-09T09:54:17.353 回答
0

您需要将 eachUIViewControllertitle属性设置为您希望后退按钮所说的内容。

相关:查看记录此行为的控制器目录文章。

于 2013-09-23T18:34:44.113 回答