Reputation: 4694
How to change the text color of the built-in textLabel
of UITablewViewHeaderFooterView
? I tried
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
guard let footer = tableView.dequeueReusableHeaderFooterView(withIdentifier: footerId) else {
return nil
}
footer.textLabel?.textColor = UIColor.blue
return footer
}
but nothing happens. My table view is of .grouped
style, if that matters
Upvotes: 0
Views: 289
Reputation: 3261
You'll have to override tableView:willDisplayFooter:forSection
for that. Somewhere between tableView:viewForFooterInSection:
and the latter, UIKit resets the textColor. Setting it in willDisplayFooter
makes sure you change it last and therefore win :).
If you register a custom UITableViewHeaderFooterView
subclass for your footer views, you may also override willMove(toWindow:)
in that class and perform your changes there.
Another alternative is to set the attributedText
property of the textLabel. UIKit won't mess with the color in that.
Upvotes: 1