UItabBarItem突出显示状态图像

时间:2009-11-08 22:10:43

标签: iphone uitabbar uitabbaritem

我希望能够在选择UITabBarItem时更改突出显示的状态图像吗?是否可以子类化并访问它?或者我需要滚动自己的导航代码吗?

- >开始编辑 我没有清楚地表达我之前想要的东西。我正在寻找设备添加到UITabBar的选定状态/图像的半透明白色覆盖参考。看图像! http://solomon71.com/images/UITabBarItem.png

2 个答案:

答案 0 :(得分:2)

没有记录或支持的方式来设置您自己的高亮显示的图像。话虽如此,在2.2中你可以通过继承UITabBarItem并实现-[UIImage *)selectedImage来实现。

严格来说,您不是在调用私有API,因为selectedImage不是保留的方法名称(实际上是某个人使用自己的合理名称)。话虽如此,我确信这不是预期的,它可能会在未来的版本中随时中断。如果在3.x中已经破坏了我就不会感到震惊(我从来没有发过任何这样的东西,只是为客户进行过实验)。

答案 1 :(得分:1)

尝试这个。

我更改了选定的tabbatitem图像,如 -

tabbar控制器委托方法

中的

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

{
    if([tabBarController selectedIndex] == 0)
    {
        [viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];
    }    
}

通过这个你可以改变你的形象。

或者您可以直接在视图控制器init(或ViewWillAppear)方法中使用,例如

        [viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];
相关问题