gpt4 book ai didi

ios - 使用 UIAppearence 更改 UIViewController 的直接 subview 的背景颜色

转载 作者:行者123 更新时间:2023-11-28 17:54:04 25 4
gpt4 key购买 nike

我想更改所有 UIViewController View 的背景颜色。我的项目中有几个 UIViewController 类,我想使用 UIAppearence 为所有 View 设置相同的背景。

我尝试了以下代码:

[[UIView appearance] setBackgroundColor:
[UIColor colorWithPatternImage:[UIImage imageNamed:@"BackgroundImage"]]];

但它改变了每个 UIView 的背景颜色,包括(UIButtonUIView 子类和 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com