我已经回答了如何为uitabbarcontroller设置图像。但是我的uitabbarcontroller是一个看起来像的视图数组:
tabBarController = [[UITabBarController alloc] init];
viewTab1controller = [[ViewTab1Controller alloc] initWithNibName:@"ViewTab1" bundle:nil];
viewTab1controller.title = @"Schedules";
navigationTab1Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab1controller] autorelease];
[viewTab1controller release];
viewTab2controller = [[ViewTab2Controller alloc] initWithNibName:@"ViewTab2" bundle:nil];
viewTab2controller.title = @"Nearest Stop";
navigationTab2Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab2controller] autorelease];
[viewTab2controller release];
viewTab3controller = [[ViewTab3Controller alloc] initWithNibName:@"ViewTab3" bundle:nil];
viewTab3controller.title = @"Routes";
navigationTab3Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab3controller] autorelease];
[viewTab3controller release];
viewTab4controller = [[ViewTab4Controller alloc] initWithNibName:@"ViewTab4" bundle:nil];
viewTab4controller.title = @"Feedback";
navigationTab4Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab4controller] autorelease];
[viewTab4controller release];
//viewTab5controller = [[ViewTab5Controller alloc] initWithNibName:@"ViewTab5" bundle:nil];
//navigationTab5Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab5controller] autorelease];
//[viewTab5controller release];
tabBarController.viewControllers = [NSArray arrayWithObjects:
navigationTab1Controller,
navigationTab2Controller,
navigationTab3Controller,
navigationTab4Controller,
//navigationTab5Controller,
我在上一个答案中获得了将图像添加到tabbaritem的代码:
viewController.tabBarItem.image = [UIImage imageNamed:@"foo.png"];
但是,这并未指定特定的tabbbaritem。
如何为这4个标签中的每一个分配图像?
谢谢! 零];
答案 0 :(得分:17)
对于您要添加到标签栏的每个View Controller,请执行以下操作:
viewTab1controller = [[ViewTab1Controller alloc] initWithNibName:@"ViewTab1" bundle:nil];
viewTab1controller.title = @"Schedules";
navigationTab1Controller = [[UINavigationController alloc] initWithRootViewController:viewTab1controller];
navigationTab1Controller.tabBarItem.image = [UIImage imageNamed:@"Match.png"];