4

我正在尝试将我自己的图像设置为 UITabBarItem 上的选定和未选定图像,但没有运气。我在视图控制器viewDidLoadviewWillAppear方法中尝试了以下代码,但都不起作用:

[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"on_rojo"] withFinishedUnselectedImage:[UIImage imageNamed:@"on"]];

我究竟做错了什么?我也读过:iOS 5: UITabBarItem setFinishedSelectedImage:withFinishedUnselectedImage: not working / ignored,但我已经在 IB 上创建了我的 UITabBarController,而不是以编程方式。这是问题吗?

先感谢您,

4

2 回答 2

13

您必须为每个选项卡项指定图像。以下代码对我有用

if ([[tabBarController.tabBar.items objectAtIndex:0] respondsToSelector:@selector(setFinishedSelectedImage:withFinishedUnselectedImage:)]) {

  [[tabBarController.tabBar.items objectAtIndex:0] setFinishedSelectedImage:[UIImage imageNamed:@"blabla1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"bleble1.png"]];
  [[tabBarController.tabBar.items objectAtIndex:1] setFinishedSelectedImage:[UIImage imageNamed:@"blabla2.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"bleble2.png"]];
  [[tabBarController.tabBar.items objectAtIndex:2] setFinishedSelectedImage:[UIImage imageNamed:@"blabla3.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"bleble3.png"]];
  [[tabBarController.tabBar.items objectAtIndex:3] setFinishedSelectedImage:[UIImage imageNamed:@"blabla4.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"bleble4.png"]];

}
于 2013-03-20T11:06:35.633 回答
0

试试这个,我用这个:

ALT标签栏

于 2013-03-20T10:49:49.263 回答