iosswiftuinavigationcontrollernavigationbarrightbarbuttonitem

Add rightBarButtonItem on second place Swift


I want to add rightBarButtonItem directly to the position of second place because I already have slider menu button on the right side of navigation bar(which is placed by third party framework and I don't have control over it). The following is the screenshot for the same with black area where I want second button for notifications.

enter image description here

Following is the code using which add it to top of slider menu button:-

let backButton = UIButton(type: UIButton.ButtonType.custom)
backButton.setImage(UIImage(named: "menulist"), for: UIControl.State())
backButton.frame=CGRect(x: 0, y: 0, width: 25, height: 25)
let rightbarButton = UIBarButtonItem(customView: backButton)
self.navigationItem.rightBarButtonItem = rightbarButton

Slider menu is a third party framework so I don't have any idea how to achieve it.

Please help and suggest some workaround.


Solution

  • You can append your new item like:

    navigationItem.rightBarButtonItems?.append(newButton)