iOS13之后使用UITabBarAppearance设置tab
2020-10-15 本文已影响0人
梁森的简书
设置方法
if (@available(iOS 13.0, *)) {
UITabBarItemAppearance *inlineLayoutAppearance = [[UITabBarItemAppearance alloc] init];
inlineLayoutAppearance.normal.titlePositionAdjustment = self.titlePositionAdjustment;
[inlineLayoutAppearance.normal setTitleTextAttributes:normalAttrs];
[inlineLayoutAppearance.selected setTitleTextAttributes:selectedAttrs];
UITabBarAppearance *standardAppearance = [[UITabBarAppearance alloc] init];
standardAppearance.stackedLayoutAppearance = inlineLayoutAppearance;
standardAppearance.backgroundColor = [UIColor cyl_systemBackgroundColor];
standardAppearance.shadowImage = [UIImage qmui_imageWithColor:UIColorHex(E5E5E5) size:CGSizeMake(SCREEN_WIDTH, PixelOne) cornerRadius:0];
self.tabBar.standardAppearance = standardAppearance;
[[UITabBar appearance] setUnselectedItemTintColor:UIColorHex(999999)]; //
}
iOS13的问题
无法成功设置tabBar未选中状态下的文字颜色
iOS14的问题
首次进入可成功设置tabBar未选中状态下的文字颜色,可当点击tabBar上某个item之后该item未选中状态下的设置的颜色无效。
解决方法
[[UITabBar appearance] setUnselectedItemTintColor:UIColorHex(999999)];
该方法可在iOS13以及之后的版本成功设置tabBar未选中状态下的文字颜色。