我在我的工具欄中創建了一個自定義barButtonItem。我想在barButtonItem被點擊時更改NSAttributedString的字符串。但是正如蘋果文檔所說,函數的性能是由customView而不是barButtonItem來支付的,我怎樣才能根據事件訪問並做一些細節變化?如何訪問和更改由UIButton組成的自定義barButtonItem的NSAttributedString標題?
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)
我是一個新swifter。 OC也可以由我讀。 歡迎任何建議。謝謝。
謝謝。終於是我的解決方案。 –