简体   繁体   中英

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM