首页 > 其他 > 详细

xcode6 自定义UITabbarController

时间:2015-01-13 19:33:14      阅读:298      评论:0      收藏:0      [点我收藏+]
-(void)initTabBarView{
    if (tabBarController && [kAPPDELEGATE.navigationController.viewControllers containsObject:tabBarController]) {
        [kAPPDELEGATE.navigationController popToViewController:tabBarController animated:YES];
        return;
    }
    [kAPPDELEGATE.navigationController popToRootViewControllerAnimated:NO];
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    NSMutableArray *controllers = [NSMutableArray array];
    
  
    //UIImageRenderingModeAlwaysOriginal 图片按照原样渲染。
    {
        SchoolSecondHandViewController *vc = [[SchoolSecondHandViewController alloc] initWithNibName:nil bundle:nil];
        UITabBarItem *item = [[UITabBarItem alloc] initWithTitle: @"首页" image:[[UIImage imageNamed:@"tabbar_home"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"tabbar_home_press"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
       
        [item setTitleTextAttributes:[NSDictionary
                                      dictionaryWithObjectsAndKeys: [UIColor redColor],
                                      NSForegroundColorAttributeName, nil] forState:UIControlStateHighlighted];
        vc.tabBarItem = item;
        [controllers addObject:vc];
    }
    {
        
        CollectSomeThingViewController *vc = [[CollectSomeThingViewController alloc] initWithNibName:nil bundle:nil];
       UITabBarItem *item = [[UITabBarItem alloc] initWithTitle: @"首页" image:[[UIImage imageNamed:@"tabbar_home"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"tabbar_home_press"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        [item setTitleTextAttributes:[NSDictionary
                                      dictionaryWithObjectsAndKeys: [UIColor redColor],
                                      NSForegroundColorAttributeName, nil] forState:UIControlStateHighlighted];
        vc.tabBarItem = item;
        [controllers addObject:vc];
        
    }
    {
        
        LossSomeThingViewController *vc = [[LossSomeThingViewController alloc] initWithNibName:nil bundle:nil];
      
        UITabBarItem *item = [[UITabBarItem alloc] initWithTitle: @"首页" image:[[UIImage imageNamed:@"tabbar_home"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"tabbar_home_press"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        [item setTitleTextAttributes:[NSDictionary
                                      dictionaryWithObjectsAndKeys: [UIColor redColor],
                                      NSForegroundColorAttributeName, nil] forState:UIControlStateHighlighted];
        vc.tabBarItem = item;
        [controllers addObject:vc];
        
    }
    {
        
        MoreViewController *vc = [[MoreViewController alloc] initWithNibName:nil bundle:nil];
        UITabBarItem *item = [[UITabBarItem alloc] initWithTitle: @"首页" image:[[UIImage imageNamed:@"tabbar_home"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"tabbar_home_press"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        [item setTitleTextAttributes:[NSDictionary
                                      dictionaryWithObjectsAndKeys: [UIColor redColor],
                                      NSForegroundColorAttributeName, nil] forState:UIControlStateHighlighted];
        vc.tabBarItem = item;
        [controllers addObject:vc];
        
    }
    
    tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
    tabBarController.delegate = self;
    tabBarController.tabBar.clipsToBounds = TRUE;
    
    {
        tabBarController.tabBar.tintColor = kDEFAULT_BG_COLOR;
        [[UITabBar appearance] setBackgroundImage:[ZQUtiles imageWithColor:kDEFAULT_BG_COLOR size:CGSizeMake(29, 1)]];//设置背景,修改颜色是没有用的
        
        [[UITabBar appearance] setSelectionIndicatorImage:[ZQUtiles imageWithColor:kDEFAULT_BG_COLOR size:CGSizeMake(29, 1)]];
    }
    [tabBarController setViewControllers:controllers];
    [kAPPDELEGATE.navigationController pushViewController:tabBarController animated:YES];
}

 

xcode6 自定义UITabbarController

原文:http://www.cnblogs.com/niit-soft-518/p/4222006.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!