美文网首页
iOS13 TabBar修改字体颜色

iOS13 TabBar修改字体颜色

作者: 路边的风景呢 | 来源:发表于2021-10-19 10:44 被阅读0次

    自己记录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];

        }

    }

    相关文章

      网友评论

          本文标题:iOS13 TabBar修改字体颜色

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