问题描述
我试图在ViewController中更改标签栏的图像,但是要显示新图像,我必须单击每个标签栏项.
I am trying to change images of my tabbar in a ViewController, but to display the new images, I must click on each tab bar item.
for (CustomTabBarItem *myItem in self.tabBarController.tabBar.items){
myItem.enabled = YES;
myItem.badgeValue = @"1";
UIImage *myImage = [[UIImage alloc] initWithContentsOfFile:[[DesignManager sharedManager] getPathOfFile:@"test.png"]];
*myItem.imageSelect= *myImage; // change images of each item. don't appear if I dont click on the item
}
任何人都知道如何直接显示这些图像?谢谢
Anyone know How can I can display directly these images?Thanks
推荐答案
您需要用新的替换旧的标签栏.否则,您将无法动态更新图像.
You need to replace the old tab bar item with a new one. You can't update the image dynamically otherwise.
最简单的方法是设置由给定选项卡表示的视图控制器的tabBarItem属性.如果您想在该视图控制器中执行此操作,只需编写:
The easiest way to do this is to set the tabBarItem property of the view-controller represented by a given tab. If you wanted to do this from within that view controller, just write:
self.tabBarItem = [[UITabBarItem alloc] initWithTitle: @"title" image: myImage: tag: nil];
或者,您可以从其他地方执行此操作,例如您的应用程序代表:
Or, you could do this from somewhere else, say your app delegate:
UIViewController* vc = [tabBarController.viewControllers objectAtIndex: 3];
vc.tabBarItem = [[UITabBarItem alloc] initWithTitle: @"title" image: myImage: tag: nil];
这篇关于重新加载/刷新ViewController中的选项卡栏项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!