IOS两种方式制作tabBar底部标签栏目
来源:互联网 发布:网络用语103是啥意思 编辑:程序博客网 时间:2024/06/05 02:29
第一种方式: //tabBar1添加 NewsViewController *news = [[NewsViewController alloc] init]; UINavViewController *nc1 = [[UINavViewController alloc] initWithRootViewController:news]; nc1.tabBarItem.title = @"栏目1"; nc1.tabBarItem.image = [UIImage imageNamed:@"menu_icon_main.png"]; [nc1.tabBarItem.title sizeWithFont:[UIFont systemFontOfSize:20]]; [news release]; //tabBar2添加 NewsViewController *news2 = [[NewsViewController alloc] init]; UINavViewController *nc2 = [[UINavViewController alloc] initWithRootViewController:news2]; nc2.tabBarItem.title = @"栏目2"; nc2.tabBarItem.image = [UIImage imageNamed:@"menu_icon_main.png"]; [nc2.tabBarItem.title sizeWithFont:[UIFont systemFontOfSize:20]]; [news2 release]; ....NSArray *item = [NSArray arrayWithObjects:nc1,nc2, nil]; //最多可添加5个栏目 UITabBarController *tabBar = [[UITabBarController alloc] init]; [tabBar setDelegate:self]; [tabBar setViewControllers:item]; [self.window setRootViewController:tabBar]; [tabBar release]; [nc1 release]; [nc2 release]第二种方式跟第一种方式稍有所不同 //tabBar1添加 NewsViewController *news = [[NewsViewController alloc] init]; UINavViewController *nc1 = [[UINavViewController alloc] initWithRootViewController:news]; [nc1.tabBarItem.title sizeWithFont:[UIFont systemFontOfSize:20]]; [news release]; //tabBar2添加 NewsViewController *news2 = [[NewsViewController alloc] init]; UINavViewController *nc2 = [[UINavViewController alloc] initWithRootViewController:news2]; nc2.tabBarItem.title = @"栏目2"; nc2.tabBarItem.image = [UIImage imageNamed:@"menu_icon_main.png"]; [nc2.tabBarItem.title sizeWithFont:[UIFont systemFontOfSize:20]]; [news2 release]; ...... NSArray *item = [NSArray arrayWithObjects:nc1,nc2, nil]; //最多可添加5个栏目 UITabBarController *tabBar = [[UITabBarController alloc] init]; UIImageView *tabImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabbarbg_app.png"]]; [tabImgView setFrame:CGRectMake(0, 436, 320, 44)]; tabBar.tabBar.backgroundImage = [UIImage imageNamed:@"tabbarbg_app.png"];//将栏目名字和栏目标识直接放在一张背景图上 [tabBar setDelegate:self]; [tabBar setViewControllers:item]; [self.window setRootViewController:tabBar]; [tabBar release]; [nc1 release]; [nc2 release];