无法更改导航项目后退按钮的文本 [英] Can't change text of navigation item back button

查看:33
本文介绍了无法更改导航项目后退按钮的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想隐藏导航栏上后退"按钮的文本,因此发现了诸如此类的过去问题:

或者,如果我尝试通过将以下内容添加到推送视图控制器的viewDidLoad中来以编程方式进行操作

  self.navigationItem.backBarButtonItem?.title =东西" 

它无效,将同一行代码移动到执行推入的视图控制器也没有作用.

无论我如何尝试更改,它怎么都不会更改?为什么使用情节提要板可以设置导航项标题,而不能设置后退按钮文本?

如果将以下内容添加到推送的视图控制器中,则可以更改文本:

  UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.clearColor()],forState:UIControlState.Normal)UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.clearColor()],forState:UIControlState.Highlighted) 

但是我想了解为什么其他尝试更改它的方法都没有效果

解决方案

后退按钮的标题自动设置为将返回的视图控制器的标题.

要执行所需的操作,您必须隐藏后退"按钮,并使用自己的图像插入自己的按钮.

烦人== @是.

I want to hide the text of the back button on the navigation bar and so have found past questions such as this: UINavigationBar Hide back Button Text

However I can't change the text at all, either via using the storyboard, or in code. See screenshot below for attempt at changing it using the storyboard:

Or if I try to do it programatically by adding the following to viewDidLoad of the pushed view controller

 self.navigationItem.backBarButtonItem?.title = "stuff"

It has no effect, nor does moving the same line of code to the view controller doing the pushing.

How come it won't change at all regardless of how I'm trying to change it? How come using the storyboard, the navigation item title can be set, but not the back button text?

If I add the following to the pushed view controller then I can get the text to change:

UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.clearColor()], forState: UIControlState.Normal)
UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.clearColor()], forState: UIControlState.Highlighted)

But I would like to understand why none of the other ways of trying to change it have any effect

解决方案

The title of the back button gets automatically set to the title of the view controller that it will go back to.

To do what you want, you'll have to hide the back button and insert your own button with your own image.

Annoying == @YES.

这篇关于无法更改导航项目后退按钮的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆