Reputation: 319
Id like to remove an icon and add text to BarButtomItem, but im not sure how to do it. here is my currrent code:
let logoutButton = UIBarButtonItem(barButtonSystemItem: .Action, target: self, action: #selector(SettingsViewController.logout))
self.navigationItem.setRightBarButtonItem(logoutButton, animated: false)
I thought i could just do UIBarButtonItem(text: "sign out", ...
but I guess that doesn't work.
Upvotes: 2
Views: 3995
Reputation: 6420
This is an old post but in case somebody else's need this, you can actually create a bar button item with just text:
let logoutButton:UIBarButtonItem = UIBarButtonItem(title:"Sign out",
style:UIBarButtonItemStyle.plain,
target:self,
action:#selector(SettingsViewController.logout))
self.navigationItem.setRightBarButtonItem(logoutButton, animated:false)
Upvotes: 0
Reputation: 3631
you can connect your UIBarButtonItem from the UI.
@IBOutlet weak var logoutButton: UIBarButtonItem!
It should look like this when you connect it.
Setting of that button can look like this
And finally put this line to ViewDidLoad func:
//Logout button
logoutButton.title = "Sign out" //This is the button title
:) It should work.
Upvotes: 1