如何使用UIAppearance appearanceWhenContainedIn:

问题描述:

我注意到在iOS5中我们可以通过UIAppearance自定义UIKit控件,并开始使用它。如何使用UIAppearance appearanceWhenContainedIn:

我想使用appearanceWhenContainedIn:定制的UINavigationBartintColor在不同的类,例如:


[[UINavigationBar appearanceWhenContainedIn:[A class], nil] setTintColor:[UIColor greenColor]]; 
[[UINavigationBar appearanceWhenContainedIn:[B class], nil] setTintColor:[UIColor redColor]]; 

然而,它完全不起作用。并且我试图在A/B类中添加如下物业:


@property (strong, nonatomic) UIColor *tintColor UI_APPEARANCE_SELECTOR; 

这似乎也没有用。

任何提示? 谢谢。

+0

对于其他UIKit控件,如UIButton,它的工作原理。但UIN​​avigationBar不起作用。可能与遏制有关。 – scorpiozj

+1

你的例子适合我(A和B是两个不同的UINavigationController子类)。 – yakovlev

我参加了ios5讨论并提出了这个问题。 就像yakovlev指出的那样,将UINavigationController进行子类化是个好主意。

+1

我已经subclassed UINavigationController但[[UINavigationBar appearanceWhenContainedIn:[A类],无] setTintColor:[UIColor greenColor]];还没有工作,我应该做任何其他配置? –