【发布时间】:2016-11-11 16:09:10
【问题描述】:
我在我的工具栏中制作了一个自定义 barButtonItem。我想在点击 barButtonItem 时更改 NSAttributedString 的字符串。但是正如苹果文档所说,该功能的性能是由customView负责的,而不是barButtonItem,我怎样才能根据事件访问并对其细节进行一些更改?
let button1 = UIButton(type: .System)
button1.sizeToFit()
let attributes1 = [NSForegroundColorAttributeName: UIColor.grayColor(), NSFontAttributeName: UIFont.systemFontOfSize(13)]
let attributedString1 = NSAttributedString(string: "Hello", attributes: attributes1)
button1.setAttributedTitle(attributedString1, forState: .Normal)
button1.addTarget(self, action: #selector(ActionViewController.switchAccounts), forControlEvents: .TouchUpInside)
let account = UIBarButtonItem(customView: button1)
setToolbarItems([account], animated: true)
我是一个新的迅捷者。 OC我也可以读。 欢迎任何建议。谢谢。
【问题讨论】:
标签: ios swift uibutton uibarbuttonitem