How to set the title bar of the right navigation bar button

How to programmatically set the title of a button on the right navigation bar. I tried

[self.navigationItem.rightBarButtonItem setTitle:@"Test"]; 

and also tried to create an output for the button, and then try to assign a value to it.

 self.rightBarButton.titleLabel.text = @"Test"; 
+6
source share
5 answers

Try the following:

 self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Test" style:UIBarButtonItemStylePlain target:target action:action]; 
+8
source

For Swift, use this,

 self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Title", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("methodName")) 

Set the title color using this,

 self.navigationItem.rightBarButtonItem?.tintColor = UIColor.whiteColor() 
+5
source

Try this, it works:

  self.navigationItem.rightBarButtonItem.title = @"New Title"; 
+3
source

This is a simple option for Swift 3:

 let rightButton = self.editButtonItem rightButton.title = "My Button" self.navigationItem.rightBarButtonItem = rightButton 
+1
source

This works for quick 3:

 navigationItem.rightBarButtonItem?.title = "Test" 

But the button must be of a non-standard type, otherwise it does not work.

0
source

Source: https://habr.com/ru/post/972595/


All Articles