ios - UIAppearance 是否在 AppDelegate 之外工作?

标签 ios appdelegate uiappearance

我已经对 UIAppearance 进行了一些尝试,它运行良好。目前我正在 AppDelegate 中设置所有外观,但现在我需要在应用程序启动后进行一些自定义(用户登录后的主题)。

是否可以将外观的东西放在 AppDelegate 之外?当然我已经试过了,但是没有效果。我是否必须重新加载整个 App-UI,如果是这样,我该怎么做?

谢谢!

克里斯

最佳答案

如果您使用 xib 创建 View ,您应该在 AppDelegate 中进行外观自定义,因为自定义应该在创建任何 UIControl 对象之前执行。您可以使用 appearanceWhenContainedIn

为不同的 View Controller /容器自定义它

To customize the appearances for instances of a class contained within an instance of a container class, or instances in a hierarchy, use +appearanceWhenContainedIn: for the appropriate appearance proxy.

例如:

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:myNavBarColor];   
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], [UIPopoverController class], nil] setTintColor:myPopoverNavBarColor];

使用ViewController类

 [[UIStepper appearanceWhenContainedIn:[MainViewController class], nil]setTintColor:[UIColor redColor]];
 [[UIStepper appearanceWhenContainedIn:[DetailViewController class], nil]setTintColor:[UIColor greenColor]];  

如果您以编程方式创建控件,无论是在创建控件之前自定义

 [[UIStepper appearance]setTintColor:[UIColor redColor]];
 UIStepper *stepper = [[UIStepper alloc]init];
 [self.view addSubview: stepper];

关于ios - UIAppearance 是否在 AppDelegate 之外工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16439029/

相关文章:

ios - UINavigationBar 外观 setBackgroundImage 隐藏状态栏

ios - 无法使用自定义单元格更改某些属性

iphone - 功能测试应该模拟 UI 事件还是检查先决条件?

ios - 从 AppDelegate 中检索最新版本的组件失败

ios - 为什么我们需要在 iOS 中单独的单例类来处理 AppDelegate 单例上的全局变量?

ios8 - UITabBar 色调颜色不适用于图像

ios - 如何为 UINavigationBar 设置不透明的 1px 高阴影图像?

ios - 表达式类型 'DataRequest' 在没有更多上下文 Swift 的情况下是不明确的

iphone - NSURLConnection 与 base64 的兼容性

ios - Cordova 插件 - 将方法附加到 AppDelegate