Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set right navigation bar button title

How do I programatically set my right navigation bar button's title. I've tried

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

and have also tried creating an outlet for the button and then trying to assign it a value.

self.rightBarButton.titleLabel.text = @"Test";
like image 501
user3626407 Avatar asked Jul 21 '14 16:07

user3626407


3 Answers

Try this:

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Test" style:UIBarButtonItemStylePlain target:target action:action];
like image 177
Sviatoslav Yakymiv Avatar answered Oct 18 '22 20:10

Sviatoslav Yakymiv


For Swift use this,

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

Set Color of Title using this,

self.navigationItem.rightBarButtonItem?.tintColor = UIColor.whiteColor()
like image 20
Mohammad Zaid Pathan Avatar answered Oct 18 '22 19:10

Mohammad Zaid Pathan


Please try this, it works:

    self.navigationItem.rightBarButtonItem.title = @"New Title";
like image 36
Harjot Singh Avatar answered Oct 18 '22 20:10

Harjot Singh