gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:13:43 25 4
gpt4 key购买 nike

我已经对 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/

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