UIAppearance在AppDelegate之外工作吗?



我已经用了一点UIAppearance,它工作得很好。目前我在AppDelegate中设置了所有的外观,但现在我需要在应用程序已经启动后做一些自定义(在用户登录后进行主题化)。

有可能把外观的东西在AppDelegate之外吗?当然我已经试过了,但是没有效果。我是否需要重新加载整个app ui,如果是这样,我该怎么做?

谢谢!

克里斯

如果你使用xib来创建你的视图,你应该在AppDelegate中进行外观定制,因为定制应该在创建任何UIControl对象之前执行。你可以使用appearanceWhenContainedIn

为不同的视图控制器/容器定制它

要为容器类的实例中包含的类的实例或层次结构中的实例定制外观,请使用+appearance whencontainedin:用于适当的外观代理。

例如:

[[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];

最新更新