Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a standard info button to a navigation bar in iOS?

I'd like to add a right bar button with the system's info icon to a navigation bar. But I see that UIBarButtonSystemItem does not provide such type of button. On the other hand, so I tried with a UIButton of type UIButtonType.infoLight, but I am not allowed to assign it to navigationItem.rightBarButtonItems.

Is there any way to do this?

like image 534
AppsDev Avatar asked Nov 29 '22 00:11

AppsDev


1 Answers

this can be achieved using UIButton object of type .infoLight

let infoButton = UIButton(type: .infoLight)
infoButton.addTarget(self, action: #selector(infoButtonTapped), forControlEvents: .TouchUpInside)
let barButton = UIBarButtonItem(customView: infoButton)
self.navigationItem.rightBarButtonItem = barButton

alternatively:

by adding infoImage to your Asset catalog and create barButtonItem using below code

let infoButton = UIBarButtonItem(image: UIImage(named: "infoImage"), style: .Plain, target: self, action: #selector(ViewController.infoButtonTapped))
self.navigationItem.rightBarButtonItem = infoButton 
like image 171
Suhit Patil Avatar answered Mar 15 '23 14:03

Suhit Patil