如何自定义tabbarcontroller

时间:2012-04-03 09:35:05

标签: iphone uitabbarcontroller

我需要将图像添加到tabbarcontroller。我将navigationcontroller作为tabbarcontroller中的tabbar项包含在内。那么如何将图像添加到tabbarcontroller。

tabBarController = [[UITabBarController alloc] init];
tabBarController.moreNavigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; 
tabBarController.moreNavigationController.topViewController.view.backgroundColor=[UIColor clearColor];  
tabBarController.delegate=self;


Dashboard_iPhone *dash = [[Dashboard_iPhone alloc] init];
UINavigationController *tabItem0 = [[[UINavigationController alloc] initWithRootViewController:dash] autorelease];
tabItem0.view.backgroundColor=[UIColor clearColor];

    TrackProgram_iPhone *rep = [[TrackProgram_iPhone alloc] init];
UINavigationController *tabItem1 = [[[UINavigationController alloc] initWithRootViewController:rep] autorelease];
tabBarController.tabBarItem.title=@"TrackProgram";  
tabItem1.view.backgroundColor=[UIColor clearColor];


TrackClinic_iPhone *loc = [[TrackClinic_iPhone alloc] init];
UINavigationController *tabItem2 = [[[UINavigationController alloc] initWithRootViewController:loc] autorelease];
tabBarController.tabBarItem.title=@"TrackClinic ";
tabItem2.view.backgroundColor=[UIColor clearColor];



tabBarController.viewControllers=[NSArray arrayWithObjects:tabItem0,tabItem1,tabItem2,nil];


[self.view insertSubview:tabBarController.view belowSubview:dash.view ];    

[self presentModalViewController:tabBarController animated:NO];

请帮我添加图片到tabbarcontroller。

2 个答案:

答案 0 :(得分:8)

self.tabBarItem.image = [UIImage imageNamed:@"CamListIconNew.png"];

将以上行添加到每个视图控制器。 此外,如果您想要自定义总标签栏。请访问以下链接。 https://github.com/boctor/idev-recipes/downloads

答案 1 :(得分:2)