Using Swift, how can I set the text in the UITableViewHeader to an attributed String?
I've tried this:
func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
// Text Color/Font
let header = view as! UITableViewHeaderFooterView
let headerString = header.textLabel?.text!
let textArr = headerString!.componentsSeparatedByString(", ")
let attributesBold = [
NSFontAttributeName : UIFont.boldSystemFontOfSize(20), NSForegroundColorAttributeName : UIColor(red: 44.0/255.0, green: 50.0/255.0, blue: 75.0/255.0, alpha: 1.0)]
let attributesNorm = [
NSFontAttributeName : UIFont.systemFontOfSize(20), NSForegroundColorAttributeName : UIColor(red: 44.0/255.0, green: 50.0/255.0, blue: 75.0/255.0, alpha: 1.0)]
var fullText = NSMutableAttributedString(string: headerString!)
let count = textArr[0].characters.count + 2 + textArr[1].characters.count + 2 //total length of bold string
fullText.addAttributes(attributesBold, range: NSRange(location: 0, length: count))
fullText.addAttributes(attributesNorm, range: NSRange(location:count, length: textArr[2].characters.count))
header.textLabel?.attributedText = fullText
}
But my iPad crashes as soon as one item is in the UITableView, and I never see the header.