Quick code to add a navigation bar button element:
Method 1 (If you want to use a button bar item)
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addTapped))
Method 2 (If you want to assign your title to a button)
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Add", style: .plain, target: self, action: #selector(addTapped))
Starting with iOS 5, it allows you to add more than one button on each side of the navigation bar. Something like that:
let add = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addTapped)) let display = UIBarButtonItem(title: "Display", style: .plain, target: self, action: #selector(playTapped)) navigationItem.rightBarButtonItems = [add, display]
iPhoneDeveloper
source share