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