として表示されるように迅速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''を作りましょう。 – Alexander