本文介绍了如何在 iOS 的导航栏中添加标准信息按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在导航栏中添加一个带有系统信息图标的右侧栏按钮.但是我看到 UIBarButtonSystemItem
没有提供这种类型的按钮.另一方面,所以我尝试使用 UIButtonType.infoLight
类型的 UIButton
,但我不允许将它分配给 navigationItem.rightBarButtonItems
.
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?
推荐答案
这可以使用 .infoLight
let infoButton = UIButton(type: .infoLight)
infoButton.addTarget(self, action: #selector(infoButtonTapped), forControlEvents: .TouchUpInside)
let barButton = UIBarButtonItem(customView: infoButton)
self.navigationItem.rightBarButtonItem = barButton
或者:
通过将 infoImage
添加到您的 Asset catalog
并使用以下代码创建 barButtonItem
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
这篇关于如何在 iOS 的导航栏中添加标准信息按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!