美文网首页
iOS13修改tabBar顶部黑线颜色以及itemTitle颜色

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

作者: 梦里桃花舞倾城 | 来源:发表于2019-10-14 09:52 被阅读0次
    • Swift
    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()
    }
    
    • OC
        
        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];
        }
    
    

    相关文章

      网友评论

          本文标题:iOS13修改tabBar顶部黑线颜色以及itemTitle颜色

          本文链接:https://www.haomeiwen.com/subject/zuvlmctx.html