The icons show fine in ios 6 but not in ios 7. I'm setting the selected state in the viewController viewDidLoad method. When the user selects a tab bar item the image disappears. Here is my code:
UITabBar *tabBar = self.tabBarController.tabBar;
if ([UITabBar instancesRespondToSelector:@selector(setSelectedImageTintColor:)]) {
[self.tabBarController.tabBar setSelectedImageTintColor:[UIColor whiteColor]];
}
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
[item0 setTitle:@"Home"];
[item1 setTitle:@"Calendar"];
[item2 setTitle:@"News"];
[item3 setTitle:@"My Events"];
[item0 setFinishedSelectedImage:[UIImage imageNamed:@"homeIconSelected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"home2.png"]];
[item1 setFinishedSelectedImage:[UIImage imageNamed:@"Calendar"] withFinishedUnselectedImage:[UIImage imageNamed:@"CalendarIconSelected"]];
[item2 setFinishedSelectedImage:[UIImage imageNamed:@"NewsIconSelected"] withFinishedUnselectedImage:[UIImage imageNamed:@"News"]];
[item3 setFinishedSelectedImage:[UIImage imageNamed:@"EventsIconSelected"] withFinishedUnselectedImage:[UIImage imageNamed:@"Events"]];
[item1 imageInsets];
[item2 imageInsets];
[item3 imageInsets];
Swift version of showing selected and unselected images and title with UIAppearance API In your Appdelegate.m copy following code if you have tab base app.following code assume you have 4 tab bar.
I had a similar problem. I created the tab bar in storyboard and added all the images through the interface builder menus, none in code.
My fix was actually simple: under the attributes inspector window in IB, the Tab Bar Item field for "Selected Image" should be blank, and the Bar Item field for "Image" should be filled with the image you want.
I am running Xcode 6.0.1 and testing with iOS 8.0.2 devices.
Use the code below to fix the image issue in iOS7:
Here is a Swift solution for Swift-Guys :)
What is exactly going on here:
Setting text colors part is important if you don't want to keep the item's title color gray for .Normal and blue for .Selected, as it is by default. This is often actual when you consider custom images for tab bar items.
Add these lines of codes in
this works for me... and hope for the best...
You should write to the function:
I hope this helps