美文网首页iOS技术收藏
iOS tabbar横线颜色及tabbar背景色设置,tabba

iOS tabbar横线颜色及tabbar背景色设置,tabba

作者: iOS门三闫 | 来源:发表于2021-01-18 10:41 被阅读0次

    1.tabbar横线颜色

    if (@available(iOS 13.0, *)) {

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

            standardAppearance.backgroundColor = [UIColor whiteColor];//根据自己的情况设置

            standardAppearance.shadowColor = [UIColor clearColor];//也可以设置为白色或任何颜色

            self.tabBar.standardAppearance = standardAppearance;

        }else{

            [[UITabBar appearance] setBackgroundImage:[[UIImage alloc]init]];

            [[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];

            [UITabBar appearance].backgroundColor = [UIColor whiteColor];//根据自己的情况设置

        }

    2.修改tabbar背景色

    - (void)setTabbarBackGround{

        if(@available(iOS 13.0, *)) {

            UITabBarAppearance *appearance = [self.tabBar.standardAppearance copy];

            appearance.backgroundImage = [selfcreateImageWithColor:[UIColor clearColor]];

            appearance.shadowImage = [selfcreateImageWithColor:[UIColor clearColor]];

            //下面这行代码最关键

            [appearance configureWithTransparentBackground];

            self.tabBar.standardAppearance = appearance;

        }else{

                [self.tabBar setBackgroundImage:[selfcreateImageWithColor:[UIColor clearColor]]];

            [self.tabBar setShadowImage:[selfcreateImageWithColor:[UIColor clearColor]]];

            self.tabBar.translucent =YES;

        }

    }

    3.设置tabbar字体颜色 大小

     if(@available(iOS 13.0, *)) {

            // iOS13 及以上

            self.tabBar.tintColor = [UIColor colorWithHexString:@"#FF0009"];

            self.tabBar.unselectedItemTintColor = [UIColor colorWithHexString:@"#333333"];

            UITabBarItem *item = [UITabBarItem appearance];

            [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} forState:UIControlStateNormal];

            [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} forState:UIControlStateSelected];

        }

        else{

            // iOS13 以下

            UITabBarItem *item = [UITabBarItem appearance];

            [item setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#333333"],NSFontAttributeName:[UIFont systemFontOfSize:14]} forState:UIControlStateNormal];

            [item setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#FF0009"],NSFontAttributeName:[UIFont systemFontOfSize:14]} forState:UIControlStateSelected];

        }

    相关文章

      网友评论

        本文标题:iOS tabbar横线颜色及tabbar背景色设置,tabba

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