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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With