Tabbar 点击 隐藏文字 图片居中


根绝需求,我们是在点击 某一个主页面的时候,将图片居中,并且不显示文字,而且其他界面效果保持原样
设置主页面代码:

- (void)setChildViewController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage

{

    vc.tabBarItem.title = title;

    if ([vc isKindOfClass:[XMNewFateViewController class]]) {

        vc.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);

    }

    if (iOS7) {

        vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

        if (boolZhi) {// 图片图层原因

            vc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

        }

        else{

           vc.tabBarItem.image = [UIImage imageNamed:image];

        }


    } else {

        vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];

        vc.tabBarItem.image = [UIImage imageNamed:image];

    }

    

    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];

    textAttrs[NSForegroundColorAttributeName] =boolZhi?[UIColor colorWithRed:247/255.0 green:186.0/255.0 blue:18/255.0 alpha:1.0]:[UIColor colorWithRed:123/255.0 green:123/255.0 blue:123/255.0 alpha:1.0];

    textAttrs[NSFontAttributeName] =  LightFont(13);//默认

    

    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];

    selectTextAttrs[NSForegroundColorAttributeName] = boolZhi?[UIColor clearColor]:ZYColor(@"#FF3455");//

    selectTextAttrs[NSFontAttributeName] = LightFont(13);

    

    

    [vc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];

    [vc.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];

    

    UIView *bgView = [[UIView alloc] initWithFrame:self.tabBar.bounds];

    bgView.backgroundColor = boolZhi?[UIColor colorWithPatternImage:[UIImage imageNamed:@"n11_label"]]:[UIColor whiteColor];//:@"tabBgImage"]

    bgView.alpha = 1;//boolZhi?1:0.3;

    [self.tabBar insertSubview:bgView atIndex:0];

    self.tabBar.opaque = YES;

    

    ZYNavigationController *zyNav = [[ZYNavigationController alloc]initWithRootViewController:vc];

    [self addChildViewController:zyNav];

   

}


☆☆☆☆☆ 点击后效果见图,直接上代码:
 在任一一个(不是每一个)主页面的Controller添加 代理方法:

-(void)tabBarController:(UITabBarController*)tabBarController didSelectViewController:(UIViewController *)viewController{

    for (UIViewController * childrenVC in tabBarController.childViewControllers) {

 if(childrenVC== tabBarController.childViewControllers[tabBarController.selectedIndex]) {

            childrenVC.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);

        }else{

            childrenVC.tabBarItem.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);

        }

    }

}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值