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

标签 ios iphone cocoa uiappearance

我想更改所有 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/

相关文章:

ios - 自定义单元格中的按钮操作不调用委托(delegate)函数

css - 移动设备上的 Wordpress 下拉菜单没有响应/工作

cocoa : Send class data to the user interface (Databinding?)

iphone - 调用addObserver和removeObserver方法的可能位置

c - 如何将0x00写入文件

android - 是否有适用于 Android 和 iPhone 的框架

ios - UIbutton 在自定义 UITableViewCell 中释放

iphone - 如何让 UIView 变得光滑 Shiny ?

iphone - 如何设置 uilabel 的高度等于 uitableviewcell

ios - 如何根据拖动/滚动或只是点击来传递点击以查看