iOS13 TabBar修改字体颜色

自己记录TabBarController的设置,有用的话很高兴帮到你,不喜勿喷!

- (void)viewDidLoad {

    [super viewDidLoad];


    [self addChildControllers];

    [self configTabBar];

    [self configTextColor];


}

#pragma mark  * * * * * * * * * * * *  CustomTabBarEvents  * * * * * * * * * * * * * * * * * *

-(void)centerButtonAction{

    NSLog(@"点击了中间凸起的按钮");

}

#pragma mark  * * * * * * * * * * * *  addChildViewController  * * * * * * * * * * * * * * * * * *

-(void)addChildControllers{

    /* 首页 */

    [self configViewController:[[JBTTLHomeVC alloc]init] titile:@"首页" selectImage:@"TabBar_Home" normalImage:@"TabBar_Home"];

    /* 帮助中心 */

    [self configViewController:[[JBTTLHelpVC alloc]init] titile:@"帮助中心" selectImage:@"TabBar_HelpCenter" normalImage:@"TabBar_HelpCenter"];

    /* 邮箱 */

    [self configViewController:[[JBTTLMailBoxVC alloc]init] titile:@"邮箱" selectImage:@"TabBar_MailBox" normalImage:@"TabBar_MailBox"];

    /* 任务 */

    [self configViewController:[[JBTTLTaskVC alloc]init] titile:@"任务" selectImage:@"TabBar_Task" normalImage:@"TabBar_Task"];

}

-(void)configViewController:(UIViewController*)controllertitile:(NSString*)titleselectImage:(NSString*)selectNamenormalImage:(NSString*)normalName{

    JBTTLNavgationController * nav = [[JBTTLNavgationController alloc]initWithRootViewController:controller];

    controller.tabBarItem.title= title;

    controller.tabBarItem.image= [UIImageimageNamed:normalName];

    controller.tabBarItem.selectedImage= [UIImageimageNamed:selectName];

    [self addChildViewController:nav];

}

#pragma mark  * * * * * * * * * * * *  自定义tabBar  * * * * * * * * * * * * * * * * * *

-(void)configTabBar{

    self.custonTabBar= [[JBTTLTabBaralloc]init];

    self.custonTabBar.delegate = self;

    [self.custonTabBar setBackgroundImage:[[UIImage alloc] init]];

    [self.custonTabBar setShadowImage:[[UIImage alloc] init]];

    // 利用KVO来使用自定义的tabBar

    [self setValue:self.custonTabBar forKey:@"tabBar"];

}

#pragma mark  * * * * * * * * * * * *  设置字体颜色  * * * * * * * * * * * * * * * * * *

-(void)configTextColor{

    if(@available(iOS13.0, *)){


        UITabBar*tabBar = [UITabBarappearance];

        [tabBarsetTintColor:UIColor.whiteColor];

        [tabBarsetUnselectedItemTintColor:UIColor.whiteColor];


    }else{


        UITabBarItem*barItem = [UITabBarItemappearance];

        [barItemsetTitleTextAttributes:@{NSForegroundColorAttributeName:UIColor.whiteColor} forState:UIControlStateNormal];

        [barItemsetTitleTextAttributes:@{NSForegroundColorAttributeName:UIColor.whiteColor}forState:UIControlStateSelected];

    }

}

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

推荐阅读更多精彩内容