Search code examples
iosswiftuikituinavigationbar

How to add a right bar button to navigation controller


How can I add a right bar button image to view controller inside a navigation controller.

I tried

let image = UIImage(named: "save") // Use your custom image or SF Symbols
let button = UIBarButtonItem(image: image, style: .plain, target: self, action: #selector(addToLibraryTapped))
navigationItem.rightBarButtonItem = button

but it does the following attached

I need the button to be smaller and to be to the far right. how can I do this?

enter image description here


Solution

  • Well if you want to add a bookmark right bar button item only then you can try this -

    navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "bookmark"), style: .plain, target: nil, action: #selector(addToLibraryTapped))