Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

ios - Can't change text of navigation item back button

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:

enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...