OC学习之UITabBarController

#import "AppDelegate.h"


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
   
    rootViewController *av = [[rootViewController alloc]init];
    self.window.rootViewController = av;
    [av release];
    
    firstViewController *first = [[firstViewController alloc]init];
    secondViewController *second = [[secondViewController alloc]init];
    thirdViewController *third = [[thirdViewController alloc]init];
    fourViewController *four = [[fourViewController alloc]init];
    fiveViewController *five = [[fiveViewController alloc]init];
    sixViewController *six = [[sixViewController alloc]init];
    UINavigationController *threeVC = [[UINavigationController alloc]initWithRootViewController:third];
    
    //把视图对象添加到数组中
    NSArray *controllerArray = [NSArray arrayWithObjects:first,second,threeVC,four,five,six, nil];
    //创建tabBar控制器
    UITabBarController *tabBarController = [[UITabBarController alloc]init];
    tabBarController.delegate = self;//设置委托
    tabBarController.viewControllers = controllerArray;//设置tabBar控制器的视图(viewControllers)
    tabBarController.selectedIndex = 0;//默认选择第一个视图填选卡(所引下标从0开始)
    
    self.window.rootViewController = tabBarController;
   
    [(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:0]setTitle:@"首页"];
     [(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:0]setImage:[UIImage imageNamed:@"icon_1_n.png"]];
    
    [(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:1]setTitle:@"信息"];
    [(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:1]setImage:[UIImage imageNamed:@"icon_2_n.png"]];
    
    [(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:2]setTitle:@"好友"];
    [(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:2]setImage:[UIImage imageNamed:@"icon_3_n.png"]];
    
    [(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:3]setTitle:@"搜索"];
    [(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:3]setImage:[UIImage imageNamed:@"icon_4_n.png"]];
    
    [(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:4]setTitle:@"更多"];
    [(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:4]setImage:[UIImage imageNamed:@"icon_5_n.png"]];
    
    //设置背景颜色
//    tabBarController.tabBar.selectedImageTintColor = [UIColor colorWithRed:1 green:0 blue:1 alpha:0];
    
//    first.title = @"one";
//    second.title = @"two";
//    third.title = @"three";
//    four.title = @"four";
//    five.title = @"five";
    
    [first release];
    [second release];
    [third release];
    [four release];
    [five release];
    [threeVC release];
    [six release];
    [self.window makeKeyAndVisible];
    return YES;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值