简体   繁体   English

如果后退按钮文本太长,则在下一行显示视图标题

[英]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.

相关问题 导航栏上的后退按钮文字太长 - Back button text too long on navigation bar 带有长文本的标题视图会推动Swift 4 iOS 11导航栏后退按钮 - Swift 4 iOS 11 navigation bar back button is pushed by a title view with long text 在iOS7中栏标题太长时,隐藏UINavigationBar后退按钮标题 - UINavigationBar back button title is hidden when the bar title is too long in iOS7 快速隐藏导航标题,但在下一视图控制器中将其标题显示为后退按钮 - Swift hide navigation title but show its title as back button in next view controller UINavigationBar后退按钮可拉伸图像太长 - UINavigationBar Back Button stretchable image too long iOS 7中缺少带有长屏幕标题的后退按钮标题 - Back button title missing with long screen title in iOS 7 SwiftUI - NavigationLink 不显示“返回”或视图的标题,除了下一个视图上的箭头 - SwiftUI - NavigationLink not showing 'Back' or title of the view besides arrow on next view 在iOS Xamarin中设置后退按钮标题文本 - set back button title text in iOS Xamarin NavigationBar BackButton的文本,如果NavigationBar的标题太长 - NavigationBar BackButton's text if NavigationBar's title is too long 使用后退按钮跳转到下一个视图控制器 - Jump to next view controller with out back button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM