当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Can't change TabBar Item icon that is set in Storyboard

问题描述:

In my app, one of the TabBar Items needs a custom icon, depending on context within the app.

I'm using this code to accomplish that:

item1 = [[UITabBarItem alloc] initWithTitle:@"Jij" image:inactiveIcon selectedImage:activeIcon];

and that works just fine. As long as I don't set an icon in the Storyboard.

In my experiments, I found out that running above code from the AppDelegate's didFinishLaunchingWithOptions executes the code before the TabBar even exists. At least that is what I think.

So, in order to have at least a temporary placeholder icon, I have to set it in the Storyboard. But somehow, that keeps my code from updating the image.

I even looked into subclassing the TabBarController, just to make sure that the icon is loaded in time.

Please point me at the mistakes in my code, logic or findings.

To summarize the question:

How come I cannot change an TabBarItem image once it is set in the Storyboard?

网友答案:

You can also set the property Render As of your tab bar images within your asset catalog directly.

There you have the option to set the property to Default, Original Image and Template Image. Hope this will help :)

分享给朋友:
您可能感兴趣的文章:
随机阅读: