本文介绍了如何在可可的uitabbarcontroller中设置单独的tabbaritem图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我回答了如何设置图像一般为uitabbarcontroller。但是我的uitabbarcontroller是一个视图数组,看起来像:

I was answered how to set images in general for a uitabbarcontroller. however my uitabbarcontroller is an array of views that looks like:

          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的代码:

I was given the code in the previous answer to add an image to a tabbaritem:

        viewController.tabBarItem.image = [UIImage imageNamed:@"foo.png"];

但是这没有指定具体的tabbbaritem。

However this doesn't specify the specific tabbbaritem.

如何为这4个标签分配图片?

How do I assign an image to each of these 4 tabs?

谢谢!
nil];

Thanks! nil];

推荐答案

对于您要添加到标签栏的每个View控制器,都会这样做:

Do it like this for each View Controller that you'll be adding to your Tab Bar:

viewTab1controller = [[ViewTab1Controller alloc] initWithNibName:@"ViewTab1" bundle:nil];
viewTab1controller.title = @"Schedules";

navigationTab1Controller = [[UINavigationController alloc] initWithRootViewController:viewTab1controller];
navigationTab1Controller.tabBarItem.image = [UIImage imageNamed:@"Match.png"];

这篇关于如何在可可的uitabbarcontroller中设置单独的tabbaritem图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 14:03