With Swift 3 / iOS 10, in the simplest case, when your navigation controller will contain only one view controller, you can use the code below to display the view controller using a toolbar containing a panel button element:
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad()
However, if you plan to have several view controllers in the navigation controller stack, you will need to call the setToolbarHidden(_:animated:) UINavigationController method in viewWillAppear() and viewWillDisappear() to correctly display or hide the built-in navigation controllers in the toolbar:
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Set the view controller toolbar items let items = [UIBarButtonItem(title: "Button Text", style: .plain, target: nil, action: nil)] setToolbarItems(items, animated: false) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) // Show navigation controller's built-in toolbar navigationController?.setToolbarHidden(false, animated: false) } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) // Hide navigation controller's built-in toolbar navigationController?.setToolbarHidden(true, animated: false) } }
source share