iOS13修改tabBar顶部黑线颜色以及itemTitle颜色

2019-10-14  本文已影响0人  梦里桃花舞倾城
if #available(iOS 13, *) {
  let appearance = self.tabBar.standardAppearance.copy()
  appearance.backgroundImage = UIImage()
  appearance.shadowImage = UIImage()
  appearance.shadowColor = .clear
  self.tabBar.standardAppearance = appearance
} else {
  self.tabBar.shadowImage = UIImage()
  self.tabBar.backgroundImage = UIImage()
}
    
    if (@available(iOS 13.0, *)) {

        UITabBarAppearance *tabBarAppearance = [[UITabBarAppearance alloc] init];

        NSMutableDictionary<NSAttributedStringKey, id> *selectedAttributes = self.tabBarAppearance.stackedLayoutAppearance.selected.titleTextAttributes.mutableCopy;
        selectedAttributes[NSForegroundColorAttributeName] = MAIN_COLOR;
        tabBarAppearance.stackedLayoutAppearance.selected.titleTextAttributes = selectedAttributes.copy;

        NSMutableDictionary<NSAttributedStringKey, id> *normalAttributes = self.tabBarAppearance.stackedLayoutAppearance.normal.titleTextAttributes.mutableCopy;
        normalAttributes[NSForegroundColorAttributeName] = COLOR_999;
        tabBarAppearance.stackedLayoutAppearance.normal.titleTextAttributes = normalAttributes.copy;
        
        tabBarAppearance.backgroundImage = [UIImage yx_createImageWithColor:WHITE_COLOR];
        tabBarAppearance.shadowColor = CX_COLOR(@"EFEFEF");
        self.tabBar.standardAppearance = tabBarAppearance;
        
        
    } else {
        
        NSMutableDictionary *selectedAttributes = [[NSMutableDictionary alloc] initWithDictionary:[[UITabBarItem appearance] titleTextAttributesForState:UIControlStateSelected]];
        selectedAttributes[NSForegroundColorAttributeName] = MAIN_COLOR;
        
        [[UITabBarItem appearance] setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected];
        [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: COLOR_999} forState:UIControlStateNormal];
        
        self.tabBar.shadowImage = [UIImage yx_createImageWithColor:CX_COLOR(@"EFEFEF")];
        self.tabBar.backgroundImage = [UIImage yx_createImageWithColor:WHITE_COLOR];
    }

上一篇下一篇

猜你喜欢

热点阅读