iOS tabBar控制器的简单使用

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self setMoRenTabBar:self];
}

- (void)setMoRenTabBar:(UITabBarController *)tabBarController
{
    // tab主题色
    tabBarController.tabBar.backgroundColor = [UIColor whiteColor];
    tabBarController.tabBar.tintColor       = [UIColor redColor];
    tabBarController.tabBar.translucent     = NO;
    tabBarController.tabBar.shadowImage     = [UIImage new]; //使用代码创建带颜色图片
    tabBarController.tabBar.backgroundImage = [UIImage new]; //使用代码创建带颜色图片
    tabBarController.tabBar.alpha = 1;
}

- (void)addChildController:(UIViewController*)childController
                     title:(NSString*)title
                 imageName:(NSString*)imageName
         selectedImageName:(NSString*)selectedImageName
                titleColor:(UIColor*)titleColor
             titleSelColor:(UIColor*)titleSelColor
                     navVc:(Class)navVc
{
    childController.view.backgroundColor = [UIColor whiteColor];
    childController.title = title;
    
    UIImage *inmage = [UIImage imageNamed:imageName];
    inmage = [inmage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childController.tabBarItem.image = inmage ;
    
    UIImage *selectedImage = [UIImage imageNamed:selectedImageName];
    selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childController.tabBarItem.selectedImage = selectedImage;
    
    // tabba默认r文字颜色
    NSDictionary *dic2 = @{ NSForegroundColorAttributeName : titleColor };
    [childController.tabBarItem setTitleTextAttributes:dic2  forState:UIControlStateNormal];
    
    // tabbar选中文字颜色
    NSDictionary *dic = @{ NSForegroundColorAttributeName : titleSelColor };
    [childController.tabBarItem setTitleTextAttributes:dic  forState:UIControlStateSelected];
    
    UINavigationController * nav = [[navVc alloc] initWithRootViewController:childController];
    [self addChildViewController:nav];
}

 

你可能感兴趣的:(标签控制器)