设置uitabBar中某个item只显示图片不显示文字,并且图片垂直居中

ios 开发中,如何设置 uitabbar 里面 tabbaritem 不显示文字,只显示图片,图片垂直居中?

-(void)creatTabbar{
    
    DisCoverViewController *webVC = [[DisCoverViewController alloc]initWithUrl:[NSString stringWithFormat:@"https://h5.axguanjia.com/iosNews.html?isApp=1&userId=%@",[MyHandle shareHandle].ID]];
    [self addChildVC:webVC title:@"发现" imageName:@"home_discover_icon_normal" selectImage:@"home_bill_icon_press"];
    
    AiXinGuanJiaLoansQuickBillViewController *billVC = [[AiXinGuanJiaLoansQuickBillViewController alloc]init];
    [self addChildVC:billVC title:@"账单" imageName:@"home_bill_icon_normal" selectImage:@"bill_add_btn"];
    
    if (![MyHandle shareHandle].ID.length) {
        [MyHandle shareHandle].ID = @"";
    }
   
    AiXinGuanJiaLoansQuickMineViewControllerSuperMarketAiXinGuanJia *mineVC = [[AiXinGuanJiaLoansQuickMineViewControllerSuperMarketAiXinGuanJia alloc]init];
    [self addChildVC:mineVC title:l10n(@"tabbar_mine_tittle") imageName:@"home_mine_icon_normal" selectImage:@"home_mine_icon_press"];
    
    [self.tabBar setBackgroundImage:[UIImage imageWithColor:typeFaceSCffffff]];
    [self.tabBar setShadowImage:[UIImage imageWithColor:kLineColor]];
    self.delegate = self;
}

-(void)addChildVC:(UIViewController *)ChildVC title:(NSString *)title imageName:(NSString *)imageName selectImage:(NSString *)selectImage{
    ChildVC.tabBarItem.title = title;
    ChildVC.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    ChildVC.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    AiXinGuanJiaMYNavigationControllerAiXinGuanJia *ChildNVC = [[AiXinGuanJiaMYNavigationControllerAiXinGuanJia alloc]initWithRootViewController:ChildVC];
    self.tabBar.tintColor = kNavcBackGroudColor;
    ChildNVC.navigationBar.tintColor = kNavcTittleColor;//设置系统自带返回按钮的颜色
    self.tabBar.translucent = NO;
    ChildVC.navigationItem.title = title;
    [[UINavigationBar appearance]
     setTitleTextAttributes:@{NSForegroundColorAttributeName:kNavcTittleColor,
                              NSFontAttributeName:[UIFont systemFontOfSize:18.f]}];
    
    [ChildNVC.navigationBar setBackgroundImage:[UIImage imageWithColor:kTabBarSelectColor] forBarMetrics:UIBarMetricsDefault];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"//去掉 api 版本问题引起的警告(引号里面是消除警告的类型)
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
#pragma clang diagnostic pop
    [self addChildViewController:ChildNVC];
    self.selectedIndex = 1;
    
    if (self.selectedIndex == 1) {
        CGFloat offset = 8.0;
        for (UITabBarItem *item in self.tabBar.items) {
            if ([item.title isEqualToString:@"账单"]) {
                item.imageInsets = UIEdgeInsetsMake(offset, 0, -offset, 0);
                item.titlePositionAdjustment = UIOffsetMake(0, 20);
            }
        }
    }
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    
    if (tabBarController.selectedIndex != 1) {
        for (UITabBarItem *item in self.tabBar.items) {
            if ([item.title isEqualToString:@"账单"]) {
                item.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);
                item.titlePositionAdjustment = UIOffsetMake(0, 0);
            }
        }
    }else{
        CGFloat offset = 8.0;
        for (UITabBarItem *item in self.tabBar.items) {
            if ([item.title isEqualToString:@"账单"]) {
                item.imageInsets = UIEdgeInsetsMake(offset, 0, -offset, 0);
                item.titlePositionAdjustment = UIOffsetMake(0, 20);
            }
        }
    }
   }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值