需要在iPhone中设置tabbar图像?

时间:2012-11-20 08:16:23

标签: iphone image tabbar

我从模板中选择了基于标签栏的应用程序。因为我需要设置我试过的自定义图像,如下所示

 UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
UINavigationController *view1=[[UINavigationController alloc]initWithRootViewController:viewController1];

UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
UINavigationController *view2=[[UINavigationController alloc]initWithRootViewController:viewController2];

UIViewController *viewController3 = [[[SecondViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil] autorelease];
UINavigationController *view3=[[UINavigationController alloc]initWithRootViewController:viewController3];

UIViewController *viewController4 = [[[SecondViewController alloc] initWithNibName:@"MainViewController" bundle:nil] autorelease];
UINavigationController *view4=[[UINavigationController alloc]initWithRootViewController:viewController4];


self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.delegate=self;


self.tabBarController.viewControllers = [NSArray arrayWithObjects:view1,view2,view3,view4, nil];

[self.tabBarController.tabBarItem setImage:[UIImage imageNamed:@"h.png"]];

我试过的另一种方式

    [[_tabBarController tabBar] setBackgroundImage:[UIImage imageNamed:@"h.png"]];

以第二种方式应用了图像,但它是背景。

所以我需要像家一样的单独按钮....

如何设置此... 谢谢....

2 个答案:

答案 0 :(得分:0)

您可以设置images UIViewControllers's中的TabBarItems ...

viewcontroller1.tabBarItems.image = [UIImage imageNamed:@"your image1"];

viewController2.tabBarItems.image = [UIImage imageNamed:@"your image2"];

viewController3.tabBarItems.image = [UIImage imageNamed:@"your image3"];

viewController3.tabBarItems.image = [UIImage imageNamed:@"your image3"];

答案 1 :(得分:0)

你可以这样做,

    NSArray *tabs =  tabBarController.viewControllers;
    UIViewController *tab1 = [tabs objectAtIndex:0];
    tab1.tabBarItem.image = [UIImage imageNamed:@"clockicon.png"];
    UIViewController *tab2 = [tabs objectAtIndex:1];
    tab2.tabBarItem.image = [UIImage imageNamed:@"nearest.png"];