I have a table view with a bunch of sections in it. I want to change the text of the sections to make it smaller and give it more character spacing.
I have overridden the following method where I change the .textLabel
property of the UITableViewHeaderFooterView
object:
func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
if let header = view as? UITableViewHeaderFooterView {
header.textLabel?.attributedText = header.textLabel?.text.flatMap {
return NSAttributedString(string: $0, attributes: [
.kern: 1.15
])
}
header.textLabel?.font = header.textLabel?.font.withSize(10)
}
}
This works, but the label isn't wide enough for the added spacing between the characters. I tried calling .sizeToFit
on both the header
and the textLabel
but it didn't work. I also tried changing the frame manually but that didn't work (the frame didn't update with my values for some reason.) How do I make the textLabel
wider so that the text with the added character spacing can fit into it?