Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the text of UIBarButtonItem programmatically?

I've read this article: Change the text of a UILabel (UIBarButtonItem) on a toolbar programmatically

But it seems not working for my auto-hide toolbar?
I also tried barbuttonItem.title to set the text, failed too.

Any idea?

like image 847
Kordan Ou Avatar asked Apr 22 '10 14:04

Kordan Ou


People also ask

How do I change my UIBarButtonItem text?

Select the UIBarButtonItem in Interface Builder , open the inspector (Command + Shift + I) , and select "Custom" under the dropdown next to Identifier .

How do I change the title of UIBarButtonItem in Swift?

In case you want to initialize UIBarButtonItem programmatically in Swift 4+ should be done as following: editButton = UIBarButtonItem(title: "Edit", style: . plain, target: self, action: #selector(editAct)).


1 Answers

Are you creating the button in Interface Builder? Make sure that the identifier is set to Custom, otherwise you will not be able to change the title.

Select the UIBarButtonItem in Interface Builder, open the inspector (Command + Shift + I), and select "Custom" under the dropdown next to Identifier.

like image 115
Pyro2927 Avatar answered Oct 16 '22 13:10

Pyro2927