Reputation: 1507
I'm adding a button to my nav view bar like this:
let navItem = UINavigationItem(title: "Waiting Room");
let doneItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.done, target: nil, action: #selector(addTapped));
navItem.leftBarButtonItem = doneItem
mainNavBar.setItems([navItem], animated: false);
The title of the view bar changes to Waiting room when I do this, but how do I change the text of the button itself that I'm adding from "Done" to something else?
I'm using Swift 4.0
Upvotes: 0
Views: 355
Reputation: 11
Try using this line of code:
buttonName.setTitle("New Title", for: .normal)
in this example, we use the setTitle(_:for:) method of the UIButton class. The first parameter is the new title you want to set, and the second parameter, .normal, specifies the state for which the title should be changed (in this case, the normal state when the button is not highlighted or disabled).
Upvotes: 0
Reputation: 6611
Try below code:
let doneItem = UIBarButtonItem(title: "Your title", style: .plain, target: self, action:#selector(addTapped));
navigationItem.leftBarButtonItem = doneItem
Hope this will help you :)
Upvotes: 3