Search code examples
swiftuinavigationbaruinavigationitemuibarbuttonsystemitem

Adding UIBarButtonSystemItem icons to Nav-Toolbar (SWIFT)


I have been trying to find a way to add the UIBarButtonSystemItem icon to the toolbar. I have implemented it on my NavBar with the following code:

self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Action, target: self, action: "shareMeme")

But when it comes to the toolbar, I am at a loss. Any ideas?


Solution

  • Try:

    var items: Array<UIBarButtonItem> = []
    
    items.append(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Action, target: self, action: "selector"))
    
    self.setToolbarItems(items as [AnyObject], animated: true)
    self.navigationController?.setToolbarHidden(false, animated: true)