UITabBarController自定义以及隐藏

首先

#import <UIKit/UIKit.h>


@interface CustomTabBar : UITabBarController


@end

- (void)viewDidLoad

{

    [superviewDidLoad];

    // Do any additional setup after loading the view.

 [selfcreateController];

}

-(void)createController{

//创建三个控制器

    DiscloseViewController * disVC = [[DiscloseViewControlleralloc]init];

    UINavigationController * disNav = [[UINavigationControlleralloc]initWithRootViewController:disVC];

    

    AnswerViewController * anVC = [[AnswerViewControlleralloc]init];

    UINavigationController * anNav = [[UINavigationControlleralloc]initWithRootViewController:anVC];

  

    MyViewController * myVC = [[MyViewControlleralloc]init];

    UINavigationController * myNav = [[UINavigationControlleralloc]initWithRootViewController:myVC];

    

    self.viewControllers =@[disNav,anNav,myNav];



    UITabBar * tabbar = self.tabBar;

    UITabBarItem * tabbaritem1 = [tabbar.itemsobjectAtIndex:0];

    UITabBarItem * tabbaritem2 = [tabbar.itemsobjectAtIndex:1];

    UITabBarItem * tabbaritem3 = [tabbar.itemsobjectAtIndex:2];

    //标题

    NSArray * titleArr = @[@"爆料",@"抢答",@"我的"];

    tabbaritem1.title = titleArr[0];

    tabbaritem2.title = titleArr[1];

    tabbaritem3.title = titleArr[2];

    //图片

    //背景图案

//    [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"mid_bg_press"]];

    //字体颜色


    NSArray * UnSelectImg=@[@"icon1_normal.png",@"icon3_normal.png",@"icon4_normal.png"];

    NSArray * SelectImg=@[@"icon1_press.png",@"icon3_press.png",@"icon4_press.png"];

    for (int i = 0 ; i < self.tabBar.items.count; i++) {

        UITabBarItem * Item =[self.tabBar.itemsobjectAtIndex:i];

        

//        [Item setFinishedSelectedImage:[UIImage imageNamed:SelectImg[i]] withFinishedUnselectedImage:[UIImage imageNamed:UnSelectImg[i]]];//IOS7之前用

        UIImage * image = [UIImageimageNamed:UnSelectImg[i]];

        image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

        Item.image = image;

        

        image = [UIImage imageNamed:SelectImg[i]];

        [Item setImageInsets:UIEdgeInsetsMake(5,0, -5,0)];

        image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

        Item.selectedImage = image;

        Item.title=titleArr[i];

        [[UITabBarItemappearance]setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColorcolorWithRed:22/256.0fgreen:177/256.0fblue:255/256.0falpha:1]}forState:UIControlStateHighlighted];//字体颜色


    }

    self.selectedIndex =1;//选中的显示控制器

}

有的页面需要隐藏返回的时候重新显示可以采用下面方法

 ChatViewController * chatController = [[ChatViewControlleralloc] initWithChatter:@"182"isGroup:NO];

    chatController.title = @"182";

 chatController.hidesBottomBarWhenPushed =YES;//隐藏

    [self.navigationControllerpushViewController:chatController animated:YES];

    chatController.hidesBottomBarWhenPushed =NO;//显示


这样就可以达到推出页面没有TabBar返回的时候重新出现的效果



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值