UITabBar在iOS 13下会有问题,比如:
1、当push进入某个页面再pop回来时,tabBar的文字颜色就会变成系统自带的蓝色
2、隐藏tabBar分割线的方法已经失效了
下面针对这两个问题做下适配
1、在原有代码基础上直接添加如下代码
if (@available(iOS 13.0, *)) {
UITabBarAppearance *appearance = [self.tabBar.standardAppearance copy];
appearance.stackedLayoutAppearance.normal.titleTextAttributes = attribute;
appearance.stackedLayoutAppearance.selected.titleTextAttributes = selectAttribute;
self.tabBar.standardAppearance = appearance;
}
2、iOS 13之前,隐藏TabBar分割线的方法是
self.tabBar.backgroundImage = [UIImage imageWithColor:[UIColor whiteColor]];
self.tabBar.shadowImage = [UIImage new];
但在iOS 13中该方法无效,所以该做如下适配
if (@available(iOS 13.0, *)) {
UITabBarAppearance *appearance = [self.tabBar.standardAppearance copy];
appearance.backgroundImage = [UIImage imageWithColor:[UIColor whiteColor]];
appearance.shadowColor = [UIColor clearColor];
self.tabBar.standardAppearance = appearance;
} else {
self.tabBar.backgroundImage = [UIImage imageWithColor:[UIColor whiteColor]];
self.tabBar.shadowImage = [UIImage new];
}
网友评论