[英]Display View Title on Next Line if Back Button Text Too Long
This is my first day trying to write an iOS app, having followed the tutorials on the Apple site and a few others, so be gentle. 这是我尝试编写iOS应用程序的第一天,已经遵循了Apple网站和其他一些网站上的教程,因此请保持柔和。 It's actually going pretty well so far!
到目前为止,实际上进展顺利!
My main view is a list of company contacts. 我的主要观点是公司联系人列表。 Tapping on a contact segues to a view showing that contact's details.
轻触联系人可以找到显示该联系人详细信息的视图。 I've embedded my views in a Navigation view, and the navigation all works fine.
我已将我的视图嵌入到导航视图中,并且导航一切正常。 On the contact details view, the view title (
self.title
) is being set to the person's name in the viewDidLoad function. 在联系人详细信息视图上,将视图标题(
self.title
)设置为viewDidLoad函数中的人员姓名。
The problem I've got is that the text of the 'back' navigation button in the title bar on the contact details view is being derived from the title of the main view, as expected, but that text is long enough to push the title of the contact detail view - the person's name - to the right, like this: 我遇到的问题是,联系人详细信息视图上标题栏中的“后退”导航按钮的文本正像预期的那样从主视图的标题派生而来,但是该文本足够长以推动标题联系人详细信息视图(此人的姓名)位于右侧,如下所示:
I was wondering if this is the expected and correct behaviour for an iOS app or if I should attempt to have the contact detail view's title displayed on a different line to the back navigation button, and, if so, how I would do that. 我想知道这是否是iOS应用程序的预期和正确行为,还是我应该尝试将联系人详细信息视图的标题显示在与后退导航按钮不同的行上,如果是这样,我将如何做。
I know that I can override the text of the back navigation button (indeed, it's automatically set to "Back" if my main controller's title is set to something a bit longer, interestingly), but that's not going to solve the problem if a person has a particularly long name! 我知道我可以覆盖后退导航按钮的文本(实际上,如果我的主控制器的标题设置得更长一些,有趣的是,它会自动设置为“后退”),但是如果有人,那将无法解决问题有一个特别长的名字!
What you're seeing is indeed the correct/expected behavior. 您所看到的确实是正确/预期的行为。
If you don't like that back button text, you can always change or remove it: 如果您不喜欢该后退按钮文本,则可以随时对其进行更改或删除:
let backButtonItem: UIBarButtonItem = UIBarButtonItem()
backButtonItem.title = "" // Set your custom text here
navigationItem.backBarButtonItem = backButtonItem
If you want to do a multi-line title you'll have to customize it by either creating your own UINavigationBar
subclass or by setting a custom titleView
on your UINavigationItem
and setting a custom view in which you render multiple lines. 如果要创建多行标题,则必须通过创建自己的
UINavigationBar
子类或在UINavigationItem
上设置自定义titleView
并设置自定义视图(在其中呈现多行)来自定义它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.