iOS中的过期方法和新的替代方法
关于iOS中的过期方法和新的替代方法
1.获取某些类的UINavigationBar的统一外观并设置UINavigationbar的背景
注:方法名改了但是基本使用方法不变
+ (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];