一锦庸、在iOS13之前敬锐,我們?nèi)コ诰€是這樣設(shè)置的
[self.tabBar setBackgroundImage:[UIImage new]];
[self.tabBar setShadowImage:[UIImage new]];
二、iOS13引入了UITabBarAppearance
類剩盒,所以我們?nèi)コ诰€需要這樣設(shè)置
if(@available(iOS 13.0, *)) {
UITabBarAppearance *appearance = [UITabBarAppearance new];
appearance.backgroundColor = [UIColor clearColor];
appearance.backgroundImage = [UIImage new];
appearance.shadowColor = [UIColor clearColor];
appearance.shadowImage = [UIImage new];
[UITabBar appearance].standardAppearance = appearance;
}
三谷婆、給tabBar
設(shè)置文字樣式,頁面跳轉(zhuǎn)返回后辽聊,在iOS13會無效纪挎,變成系統(tǒng)藍(lán)了
- (void)addChildVc:(UIViewController *)childVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
// 設(shè)置子控制器的文字
childVc.title = title; // 同時(shí)設(shè)置tabbar和navigationBar的文字
// 設(shè)置子控制器的圖片
childVc.tabBarItem.image = [[UIImage imageNamed:image]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// 設(shè)置文字的樣式
NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
textAttrs[NSForegroundColorAttributeName] = kHexColor(0x939393);
NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
selectTextAttrs[NSForegroundColorAttributeName] = kHexColor(0x1A1A1A);
[childVc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
[childVc.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
[self addChildViewController:childVc];
}
解決:也是iOS13新加的UITabBarAppearance
類有關(guān)
- (void)addChildVc:(UIViewController *)childVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
// 設(shè)置子控制器的文字
childVc.title = title; // 同時(shí)設(shè)置tabbar和navigationBar的文字
// 設(shè)置子控制器的圖片
childVc.tabBarItem.image = [[UIImage imageNamed:image]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// 設(shè)置文字的樣式
NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
textAttrs[NSForegroundColorAttributeName] = kHexColor(0x939393);
NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
selectTextAttrs[NSForegroundColorAttributeName] = kHexColor(0x1A1A1A);
[childVc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
[childVc.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
// 解決出現(xiàn)系統(tǒng)藍(lán)問題
if(@available(iOS 13.0, *)) {
UITabBarAppearance *appearance = [UITabBarAppearance new];
// 設(shè)置未被選中的顏色
appearance.stackedLayoutAppearance.normal.titleTextAttributes = @{NSForegroundColorAttributeName: kHexColor(0x939393)};
// 設(shè)置被選中時(shí)的顏色
appearance.stackedLayoutAppearance.selected.titleTextAttributes = @{NSForegroundColorAttributeName: kHexColor(0x1A1A1A)};
[UITabBar appearance].standardAppearance = appearance;
}
[self addChildViewController:childVc];
}