如何在不进入viewcontroller的情况下更改tabbar中的图像?

时间:2012-08-02 12:48:19

标签: iphone ios ipad

我有一个IPhone应用程序,其中我使用tabbar的自定义图像。当选择tabbar我必须显示一个图像并取消选择显示另一个。我已经成功实现了通过使用appdelegate中的波纹管代码。 `

 UIImage *selectedImage0 = [UIImage imageNamed:@"pinboard_hvr2.png"];
    UIImage *unselectedImage0 = [UIImage imageNamed:@"pinboard2.png"];



    UIImage *selectedImage2 = [UIImage imageNamed:@"scan_hvr2.png"];
    UIImage *unselectedImage2 = [UIImage imageNamed:@"scan2.png"];

    UIImage *selectedImage3 = [UIImage imageNamed:@"places_hvr2.png"];
    UIImage *unselectedImage3 = [UIImage imageNamed:@"places2.png"];


    UITabBar *tabBar = self.tabBarController.tabBar;
    tabBar.TintColor = [UIColor clearColor];
    UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
    UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
    UITabBarItem *item2 = [tabBar.items objectAtIndex:2];


    [item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
    [item1 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
    [item2 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];

`但是现在我的问题是我在secondindex中有一个教程视图。点击该按钮时我需要根据教程中的说明更改每个tabbar图标。但我不需要去。我想留在教程视图本身。但需要更改图标。可以帮助我实现这个目标吗?

2 个答案:

答案 0 :(得分:1)

最后我已经解决了问题。实际上它是一个简单的东西。根据教程按钮动作设置你选择和取消选择的图像。例如,如果你有3个按钮,那里显示每个标签的重要性设置appdelegate的选定图像.tabbar根据这样的观点。

TabNavAppDelegate *appdelegate = ( TabNavAppDelegate *)[[UIApplication sharedApplication] delegate];

    UIImage *unselectedImage0 = [UIImage imageNamed:@"pinboard_hvr2.png"];
    UIImage *unselectedImage2 = [UIImage imageNamed:@"scan2.png"];

    UIImage *selectedImage3 = [UIImage imageNamed:@"places2.png"];
    UITabBar *tabBar = appdelegate.tabBarController.tabBar;
    tabBar.TintColor = [UIColor clearColor];
    UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
    UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
    UITabBarItem *item2 = [tabBar.items objectAtIndex:2];


    [item0 setFinishedSelectedImage:unselectedImage0 withFinishedUnselectedImage:unselectedImage0];
    [item1 setFinishedSelectedImage:unselectedImage2 withFinishedUnselectedImage:unselectedImage2];
    [item2 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:selectedImage3];

`并在第三个按钮操作中将其设置回正常方式,就像在appdelegate中一样。

答案 1 :(得分:0)

向AppDelegate发送通知或调用委托方法。在该方法中,您还可以根据需要传递参数,并在那里进行特定的选项卡更改。

希望这对你有用。