我正在尝试普遍更改表格 View 的背景颜色。它是 UINavigationController 和 TabBarController 应用程序的组合。我尝试将以下内容放入 AppDelegate applicationDidFinishLaunchingWithOptions
[[[UITableView appearance] backgroundView] setBackgroundColor:[UIColor redColor]];
[[UITableView appearance] setBackgroundColor:[UIColor redColor]];
[[UITableView appearanceWhenContainedIn:[UINavigationController class], nil] setBackgroundColor:[UIColor greenColor]];
[[UITableView appearanceWhenContainedIn:[UITabBarController class], nil] setBackgroundColor:[UIColor greenColor]];
没有变化。
如果我尝试更改 AppDelegate 中的常规 UIView,这有效:
[[UIView appearance] setBackgroundColor:[UIColor redColor]];
如果我在 viewDidLoad 中单独攻击每个 tableview,这会起作用:
self.tableView.backgroundColor = [UIColor redColor];
我意识到这只是一行代码,但是有很多 View ,这只是另一件事需要跟踪。 iOS 5 UIAppearance 似乎就是为此而设计的。我不清楚为什么它不起作用。谢谢。
最佳答案
UIAppearance
在技术上不支持 setBackgroundColor:
,这就是为什么您没有看到所有表格 View 颜色发生变化的原因。您最好的选择是子类化 UITableView
。
如果您需要有关如何执行此操作的信息,请参阅 this answer.
对于 future 的观众,here是指向答案的链接,其中包含 UIAppearance
支持的所有方法的列表。
关于ios - 使用 UIAppearance 设置 UITableView 的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16751067/