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

  • 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];
    }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容