I have created a simple UIViewController which contains a UITableView. When adding a tableHeaderView which includes a UIButton it seems not to be possible to change the button label using appearance settings. Other buttons outside the tableHeaderView are updated correctly.
Here the button which was placed directly in the ViewControllers view is updated correctly while the appearance settings seem not to effect the button inside the tableHeaderView.
class ListViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableHeaderView: UIView!
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
UILabel.appearance(whenContainedInInstancesOf: [TestButton.self]).font = UIFont.systemFont(ofSize: 30)
UILabel.appearance(whenContainedInInstancesOf: [TestButton.self]).textColor = .red
super.viewDidLoad()
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
tableView.tableHeaderView = tableHeaderView
}
...
}
class TestButton: UIButton {}
There are now other appearance settings in the project which might explain this. Moving the appearance settings to some other place, e.g. application:didFinishLaunchingWithOptions does not change the problem.
Is this a bug or am I missing something?


That will likely not be a suitable approach.
A
UIButtondoes various things with itstitleLabel- including changing the text color.Trying to use
UILabel.appearance(...)will not override the normal behavior.You can see this by running your code as-is:
TestButtondoes get the appearanceThis is the same reason why we use:
instead of:
You probably want to configure those properties in your custom
TestButtonclass. Here's the basics: