#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;
}
OC学习之UITabBarController
最新推荐文章于 2020-07-20 15:52:08 发布