I am developing a shopping cart tab. Initially, I simply use the default icon value to show how many items are in the basket on the bottom tab. Now the designer wants to be a fantasy, he wants to show another image based on the number of items in the basket. For example, if there is, show cartTab-1.png, if 2, show cartTab-2.png ...
I tried changing the tabaritem image ( UITabBarItem ), but this did not work for me. Is it possible? I discussed with my colleague, he said that I may have to draw an image on top of the tab. Do you have any suggestions? thanks
more details:
- I created a tabItem using InterfaceBuilder and installed the image and name there.
- I need to support ios4. Therefore, I cannot use setSelectedImage ...
- In my case, this is KVO, if the basket counter changes, it notifies about the method of updating the image. not at the initialization stage.
Does anyone know why [self.tabBarItem setImage:[UIImage imageNamed:@"cartxxx.png"]] does not work? When I debug, the property changes, but the user interface remains the same
Update
below code works. Thanks to all!
UIImage* cartTabImage = [UIImage imageNamed:cartTabImageName]; [[self.tabBarController.tabBar.items objectAtIndex:3] setImage:cartTabImage];
source share