如何为 UIBarButtonItem 设置标题? [英] How do I set title for UIBarButtonItem?
本文介绍了如何为 UIBarButtonItem 设置标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一名初学 iPhone 开发者.
I'm a beginner iPhone developer.
如何以编程方式设置 UIBarButtonItem
的标题?
How can I programmatically set the title for the UIBarButtonItem
?
我的代码如下:
self.navigationItem.rightBarButtonItems =
UIBarButtonItem(
barButtonSystemItem: .Cancel, target: self,
action: "barButtonItemClicked:")
@IBAction func barButtonItemClicked(sender: UIBarButtonItem) {
//print something
}
推荐答案
使用不同的初始化器,允许你指定标题:
Use different initialiser that allows you to specify the title:
UIBarButtonItem(title: "title", style: .Plain, target: self, action: "barButtonItemClicked:")
Swift 3.1 更新
UIBarButtonItem(title: "title", style: .plain, target: self, action: #selector(barButtonItemClicked))
这篇关于如何为 UIBarButtonItem 设置标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文