我改變表格視圖節標題的最後一個字符的顏色和我得到的iOS 9+一個奇怪的結果,迅速3.可變的字符串的顏色變化改變字符顯示爲方形
的最後一個字符是複選標記✔︎,顏色是綠色。結果是綠色正方形而不是綠色複選標記。如果我打印控制檯複選標記顯示正確。如果我刪除顏色變化,它會顯示覆選標記(黑色)。如果我使用另一個符號,如雙重感嘆號,‼
它工作得很好。
簡化的代碼
struct PersonConstants{
static let DEFAULT_STATUS_INDEX : Int = 1
static let validStatus : NSArray = ["✔︎","?","‼"]
}
let colorsArray = [
UIColor(red: 29/255.0, green:166/255.0, blue:47/255.0, alpha:1.0),
UIColor(red: 0/255.0, green: 0/255.0, blue: 255/255.0, alpha: 1.0),
UIColor(red: 225/255.0, green: 0/255.0, blue: 0/255.0, alpha: 1.0),
]
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?{
var title = String(Safe.count) + " "
title += NSLocalizedString("Accounted", comment: "")
title += ": " + String(PersonConstants.validStatus[0] as! NSString)
return title
}
override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
if let view = view as? UITableViewHeaderFooterView {
view.textLabel!.textColor = UIColor.black
view.textLabel!.font = UIFont.italicSystemFont(ofSize: 17.0)
myMutableString = NSMutableAttributedString(string: view.textLabel!.text! as String)
if sectionTwo.count > 0{
myMutableString.addAttribute(NSForegroundColorAttributeName, value: colorsArray[0], range: NSRange(location: (view.textLabel!.text!).characters.count-1,length:1))
view.textLabel!.attributedText = myMutableString
//print(myMutableString.string)
}else{
view.textLabel!.text = ""
}
}
}
壞的結果
'String(PersonConstants.val idStatus [0] as! NSString)''拿一個'String',把它變成一個'NSString',然後用它來創建一個'String'.Wut。 – Alexander