+ (instancetype)appearanceWhenContainedIn:(nullable Class <UIAppearanceContainer>)ContainerClass, ... NS_REQUIRES_NIL_TERMINATION NS_DEPRECATED_IOS(5_0, 9_0, "Use +appearanceWhenContainedInInstancesOfClasses: instead");
+ (instancetype)appearanceWhenContainedInInstancesOfClasses:(NSArray<Class <UIAppearanceContainer>> *)containerTypes NS_AVAILABLE_IOS(9_0);
使用案例
NSArray *array = [NSArray arrayWithObjects:[self class], nil];
UINavigationBar *bar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses: array];
[bar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
补充:
//所有的都一样
UINavigationBar *bar = [UINavigationBar appearance];
//只有属于数组中的类才生效,并进行设置
UINavigationBar *bar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses: array];