I created a simple project with a UINavigationController, a UIBarButtonItem on the right, and a UITableView. For testing, I want to use appearanceWhenContainedIn: to color the UIBarButtonItems on the UINavigationController orange while also coloring UIButtons in the UITableView red. Alone, each styling works correctly. But when I use both together, it doesn't work. Why??
Scenario 1 (Color UIBarButtonItem in UINavigationController):
[[UIBarButtonItem
appearanceWhenContainedIn:[UINavigationController class], nil]
setTintColor:[UIColor orangeColor]];

Scenario 2 (Color UIButton in UITableView):
[[UIButton
appearanceWhenContainedIn:[UITableView class], nil]
setTintColor:[UIColor redColor]];

Scenario 3 (Combine them):
[[UIButton
appearanceWhenContainedIn:[UITableView class], nil]
setTintColor:[UIColor redColor]];
[[UIBarButtonItem
appearanceWhenContainedIn:[UINavigationController class], nil]
setTintColor:[UIColor orangeColor]];

Sample project can be downloaded via this link: https://www.dropbox.com/s/k7nabaqc9oso907/AppBugTesting.zip
Update: As I continue to diagnose the problem, I found that if I use "setBackgroundColor" of the UIButton to red rather than setTintColor, it shows the red background and the orange tint to the UIBarButtonItem. For some reason tinting both doesn't work... still not sure why.
This works:
[[UIButton
appearanceWhenContainedIn:[UITableView class], nil]
setTintColor:[UIColor redColor]];
[[UINavigationBar
appearanceWhenContainedIn:[UINavigationController class], nil]
setTintColor:[UIColor orangeColor]];
Of course this might turn some other things orange that you didn't intend.
I would create "empty" UITableView and UINavigationController subclasses to refer to, so as to avoid accidentally changing the appearance of other buttons.
[[UIButton
appearanceWhenContainedIn:[MyTableView class], nil]
setTintColor:[UIColor redColor]];
[[UINavigationBar
appearanceWhenContainedIn:[MyNavigationController class], nil]
setTintColor:[UIColor orangeColor]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With