我正在尝试普遍更改表格视图的背景颜色。它是 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 中单独攻击每个表视图,则这是有效的:
self.tableView.backgroundColor = [UIColor redColor];
我意识到这只是一行代码,但是有很多视图,这只是另一件事需要跟踪。 iOS 5 UIAppearance 似乎就是为此而设计的。我不清楚为什么它不起作用。谢谢。
UIAppearance
技术上不支持setBackgroundColor:
,这就是为什么您没有看到所有表视图颜色发生变化的原因。你最好的选择是子类化UITableView
.
如果您需要有关如何执行此操作的信息,请参阅这个答案。 https://stackoverflow.com/a/3445925/817946
对于未来的观众来说,here https://stackoverflow.com/a/9424142/817946是指向答案的链接,其中包含所支持的所有方法的列表UIAppearance
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)