2016-03-04 17 views

回答

-1

你需要如果你想這對工作的UIBarButtonItem使用NSMutableAttributedString

let yourString = NSMutableAttributedString(string: "[Count:1]",attributes: attrs!]) 

yourString.addAttribute(attrs!, range: range) 

yourButton.text = yourString 
+0

的UIBarButtonItem不有一個addAttribute方法。 –

+0

編輯完成後立即嘗試,因爲錯誤。 – xyaz

1

你需要使用一個customView像這樣:

let yourString = NSMutableAttributedString(string: "Count: 1") 
yourString.setAttributes(attrs, range: range) 
let buttonLabel = UILabel() 
buttonLabel.attributedText = yourString 
buttonLabel.sizeToFit() // Important for bar buttons 
let barButton = UIBarButtonItem(customView: buttonLabel)