我想更改所有 UIViewController
View 的背景颜色。我的项目中有几个 UIViewController
类,我想使用 UIAppearence
为所有 View 设置相同的背景。
我尝试了以下代码:
[[UIView appearance] setBackgroundColor:
[UIColor colorWithPatternImage:[UIImage imageNamed:@"BackgroundImage"]]];
但它改变了每个 UIView 的背景颜色,包括(UIButton
、UIView
子类和 UILabels
等)
有什么方法可以处理这种情况,让我只能更改 UIViewController
View 的背景颜色?我谷歌了很多,但我没有找到任何相关的解决方案。
如有任何帮助,我们将不胜感激。
谢谢..
最佳答案
嗯,我认为最好的方法是继承 UIViewController 并在 viewDidLoad 中设置 backgroundColor。但是如果你想使用 UIAppearance 你可以这样做:
id proxy = [UIView appearanceWhenContainedIn:[UIViewController class],nil];
[proxy setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"BackgroundImage"]]
关于ios - 使用 UIAppearence 更改 UIViewController 的直接 subview 的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20309049/