UITabBar does not display selected item images in ios 7

The icons are clearly visible in ios 6, but not in ios 7. I set 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]; 
+45
objective-c ios7 uitabbar
Sep 19 '13 at 12:46 on
source share
20 answers

You need to use tabBarItem initWithTitle:image:selectedImage

 [[UITabBarItem alloc] initWithTitle:@"title" image:image selectedImage:imageSel]; 

combined with changing the UIImage rendering mode:

 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal 

or (to apply the hue mask to the parent view template, this is the default option for tab bar items unless you opt out of the above rendering mode)

 imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate 

Here is a sample code for a single tab bar item: -

 UIImage *musicImage = [UIImage imageNamed:@"music.png"]; UIImage *musicImageSel = [UIImage imageNamed:@"musicSel.png"]; musicImage = [musicImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; musicImageSel = [musicImageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; self.musicViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Music" image:musicImage selectedImage:musicImageSel]; 

Hope this helps

+96
Sep 19 '13 at 17:26
source share

Setting the image rendering mode to the position of the original item can solve this problem. This can be done using images in .xcassets, so you do not need to write a lot of codes.

The first step is to drap & drop your hatch images in Assets.xcassets.

In the second step, select the image of the panel element and change [Render As] to [Original Image]

enter image description here

ps: I usually set the TabBarController tab bar items in the story bar so as not to write a lot of code.

enter image description here

+45
Oct 21 '15 at 8:45
source share

Add these lines of code to

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; UITabBar *tabBar = tabBarController.tabBar; UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0]; UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1]; UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2]; UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3]; tabBarItem1.selectedImage = [[UIImage imageNamed:@"selectimg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; tabBarItem1.image = [[UIImage imageNamed:@"deselectimg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; tabBarItem1.title = @"xxxx"; tabBarItem2.selectedImage = [[UIImage imageNamed:@"selectimg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; tabBarItem2.image = [[UIImage imageNamed:@"deselectimg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; tabBarItem2.title = @"xxxx"; tabBarItem3.selectedImage = [[UIImage imageNamed:@"selectimg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; tabBarItem3.image = [[UIImage imageNamed:@"deselectimg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; tabBarItem3.title = @"xxxx"; tabBarItem4.selectedImage = [[UIImage imageNamed:@"selectimg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; tabBarItem4.image = [[UIImage imageNamed:@"deselectimg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; tabBarItem4.title = @"xxxx"; return YES; } 

it works for me ... and hope for the best ...

+44
Sep 23 '13 at 6:35
source share

No answers helped fix this problem. The main reason is because my TabBarController not my RootViewController .

The solution I used for the storyboard and just clicked on my UITabButton and I added the runtime attribute for selectedImage :

For each of the different views associated with the UITabController .

+16
May 13 '15 at 13:02
source share

After spending a couple of hours trying to get my custom tab to work for both iOS 6 and 7, this is what worked for me ...

 UITabBarController *tabBarController = (UITabBarController *)[[self window] rootViewController]; UITabBar *tabBar = tabBarController.tabBar; UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0]; UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1]; UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2]; UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3]; tabBarItem1.title = @"Home"; tabBarItem2.title = @"Map"; tabBarItem3.title = @"Weather"; tabBarItem4.title = @"Info"; if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) { [tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"cyexplore_home_white.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"cyexplore_home_black.png"]]; [tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"cyexplore_cloud_white.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"cyexplore_cloud_black.png"]]; [tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"cyexplore_map_white.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"cyexplore_map_black.png"]]; [tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:@"cyexplore_info_white.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"cyexplore_info_black.png"]]; } else { tabBarItem1.selectedImage = [[UIImage imageNamed:@"cyexplore_home_white"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; tabBarItem1.image = [[UIImage imageNamed:@"cyexplore_home_black"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; tabBarItem2.selectedImage = [[UIImage imageNamed:@"cyexplore_cloud_white"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; tabBarItem2.image = [[UIImage imageNamed:@"cyexplore_cloud_black"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; tabBarItem3.selectedImage = [[UIImage imageNamed:@"cyexplore_map_white"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; tabBarItem3.image = [[UIImage imageNamed:@"cyexplore_map_black"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; tabBarItem4.selectedImage = [[UIImage imageNamed:@"cyexplore_info_white"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; tabBarItem4.image = [[UIImage imageNamed:@"cyexplore_info_black"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; } UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"]; [[UITabBar appearance] setBackgroundImage:tabBarBackground]; [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_selected.png"]]; [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], UITextAttributeTextColor, nil] forState:UIControlStateNormal]; [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor, nil] forState:UIControlStateSelected]; 
+9
Nov 21 '13 at 0:26
source share

If you work with paging pages, you need to put the identifier: "custom" in the Navigation Controller.

then:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Assign tab bar item with titles UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; UITabBar *tabBar = tabBarController.tabBar; UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0]; UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1]; UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2]; (void)[tabBarItem1 initWithTitle:nil image:[UIImage imageNamed:@"home.png"] selectedImage:[UIImage imageNamed:@"home_selected.png"]]; (void)[tabBarItem2 initWithTitle:nil image:[UIImage imageNamed:@"home.png"] selectedImage:[UIImage imageNamed:@"home_selected.png"]]; (void)[tabBarItem3 initWithTitle:nil image:[UIImage imageNamed:@"home.png"] selectedImage:[UIImage imageNamed:@"home_selected.png"]]; // Change the tab bar background UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"]; [[UITabBar appearance] setBackgroundImage:tabBarBackground]; return YES; } 

This works for me.

+8
Oct 23 '13 at 23:38
source share

None of the answers worked for me - I use MonoTouch, but if you set the TintColor property of UITabBar itself, which will highlight the selected image with this color. In obj c, there may be a setTintColor function.

+3
Oct 15 '13 at 16:19
source share

I had the same problem with Xcode 6.0.1 (6A317), it seems to be an error with the interface builder. However, I managed to solve this problem by leaving the selected image blank in the interface builder, and then in each viewDidLoad in my controllers that I inserted:

[self.navigationController.tabBarItem setSelectedImage:[UIImage imageNamed:@"imagename-selected"]];

Now it works well, showing my selectedImage and with a global hue mask.

+3
Oct 07 '14 at 12:45
source share

Based on the answer from 132206, I made this method for AppDelegate, called from application:didFinishLaunchingWithOptions: with:

[self configureSelectedImages];

This clearly requires a strict naming convention for your tab images, but can also be reused without editing. To indicate the obvious - name the tabs you selected TabbarXXXSelected, where XXX is the name of the tab bar item.

 - (void)configureSelectedImages { UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; UITabBar *tabBar = tabBarController.tabBar; for (UITabBarItem *tabBarItem in [tabBar items]) { NSString *selectedImage = [NSString stringWithFormat:@"Tabbar%@Selected", [tabBarItem title]]; (void)[tabBarItem initWithTitle:[tabBarItem title] image:[tabBarItem image] selectedImage:[UIImage imageNamed:selectedImage]]; } } 
+2
Nov 19 '13 at 9:09 on
source share

You should write functions:

 UIImage* tab_image = [UIImage imageNamed:@"tab_image.png"]; UIImage* tab_image_selected = [UIImage imageNamed:@"tab_image_selected.png"]; tab_image = [tab_image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; tab_image_selected = [tab_image_selected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; self.tabBarItem.image = tab_image; self.tabBarItem.selectedImage = tab_image_selected; 

I hope this helps

+2
Dec 12 '13 at 16:23
source share

In your first .h controller file, I added the following: @property (weak, non-atomic) IBOutlet UITabBarItem * mapViewTabBarItem; @property (weak, non-atomic) IBOutlet UITabBarItem * profileViewTabBarItem; @property (weak, non-atomic) IBOutlet UITabBarItem * notificationViewTabBarItem;

(note that mapViewTabBarItem was linked by ctrl by dragging the actual tab element into the list of property declarations at the top of the .h file)

Next, in the same view .m file in viewDidLoad, add the following:

 self.tabBarItem = [self.tabBarController.tabBar.items objectAtIndex:0]; _mapViewTabBarItem.selectedImage = [[UIImage imageNamed:@"@2x-map-icon-selected.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; self.tabBarItem.image = [[UIImage imageNamed:@"@2x-map-icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; _profileViewTabBarItem = [self.tabBarController.tabBar.items objectAtIndex:1]; _profileViewTabBarItem.selectedImage = [[UIImage imageNamed:@"@2x-profile-icon-selected.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; _profileViewTabBarItem.image = [[UIImage imageNamed:@"@2x-profile-icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; _notificationViewTabBarItem = [self.tabBarController.tabBar.items objectAtIndex:2]; _notificationViewTabBarItem.selectedImage = [[UIImage imageNamed:@"@2x-notifications-icon-selected.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; _notificationViewTabBarItem.image = [[UIImage imageNamed:@"@2x-notifications-icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; 
+2
Jun 23 '14 at 7:05
source share

I had a similar problem. I created a tab bar in the storyboard and added all the images through the interface builder menu, not one in the code.

My correction was actually simple: in the attribute inspector window in IB, the tab tab field for "Selected Image" should be empty, and the "Item Position" field for "Image" should be filled with the desired image.

I am running Xcode 6.0.1 and testing with iOS 8.0.2 devices.

+2
01 Oct '14 at 20:07
source share

Try the following:

 UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"Icon-Small-50.png"] tag:100]; UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"image-50.png"] tag:200]; UITabBarItem *item3 = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"Icon-clip-50.png"] tag:300]; UITabBarItem *item4 = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"Icon-color-50.png"] tag:400]; UITabBarItem *item5 = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"Icon-lock-50.png"] tag:500]; [item1 setSelectedImage:[[UIImage imageNamed:@"Icon-Small-50.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; [item1 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; [item2 setSelectedImage:[[UIImage imageNamed:@"image-50.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; [item2 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; [item3 setSelectedImage:[[UIImage imageNamed:@"Icon-clip-50.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; [item3 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; [item4 setSelectedImage:[[UIImage imageNamed:@"Icon-color-50.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; [item4 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; [item5 setSelectedImage:[[UIImage imageNamed:@"Icon-lock-50.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; [item5 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; item1.image = [[UIImage imageNamed:@"Icon-Small-50.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item2.image = [[UIImage imageNamed:@"image-50.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item3.image = [[UIImage imageNamed:@"Icon-clip-50.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item4.image = [[UIImage imageNamed:@"Icon-color-50.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item5.image = [[UIImage imageNamed:@"Icon-lock-50.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
+1
May 07 '15 at 9:23
source share

I had the same problem. But working with StoryBoards prevented me from changing anything in the code. Leaving the image omitted from the storyboard removed this obstacle for me. However, placing initWithTitle in the viewWillAppear method in the viewcontroller window gave me strange behavior. First, an additional click was required to obtain the selected image, and images were not displayed for non-initial tabs.

For me it was adding the following code to AppDelegate in DidFinishLoadingWithOptions (similar to 132206 and Amitabha):

 NSArray * vcs = [(UITabBarController*)self.window.rootViewController viewControllers]; UIViewController *tab0 = [[(UINavigationController*)[vcs objectAtIndex:0] viewControllers] objectAtIndex:0]; tab0.title = NSLocalizedString(@"Time", nil); tab0.tabBarItem = [[UITabBarItem alloc] initWithTitle:tab0.title image:[UIImage imageNamed:@"Recents.png"] selectedImage:[UIImage imageNamed:@"RecentsSolid.png"]]; UIViewController *tab1 = [[(UINavigationController*)[vcs objectAtIndex:1] viewControllers] objectAtIndex:0]; tab1.title = NSLocalizedString(@"Expense", nil); tab1.tabBarItem = [[UITabBarItem alloc] initWithTitle:tab1.title image:[UIImage imageNamed:@"Euro.png"] selectedImage:[UIImage imageNamed:@"EuroSolid.png"]]; 
0
Nov 20 '13 at 10:19
source share

Use the following code to fix the image problem in iOS7:

 [[UITabBarItem alloc] initWithTitle:@"title" image:[[UIImage imageNamed:@"YOUR_IMAGE.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"YOUR_SEL_IMAGE.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 
0
Dec 17 '13 at 13:00
source share

This is an easy and clean category solution for UITabBar elements.

Just create a category and use the Runtime Attribute and put it out of the category as shown below. Add Runtime Attribute for selected TabBarItemRefer it from category and make changes

 #import "UITabBarItem+CustomTabBar.h" @implementation UITabBarItem (CustomTabBar) -(void)setValue:(id)value forKey:(NSString *)key { if([key isEqualToString:@"tabtitle"]){ if([value isEqualToString:@"contacts"]) { [self setSelectedImage:[[UIImage imageNamed:@"contacts-selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; } else if([value isEqualToString:@"chat"]) { [self setSelectedImage:[[UIImage imageNamed:@"chat-selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; } else if([value isEqualToString:@"groupchat"]) { [self setSelectedImage:[[UIImage imageNamed:@"groupchat-selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; } else if([value isEqualToString:@"settings"]) { [self setSelectedImage:[[UIImage imageNamed:@"settings-selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; } } [self setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Roboto-Regular" size:12.0f], NSFontAttributeName, [UIColor grayColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal]; } @end 
0
Jul 10 '15 at 4:02
source share

Old questions, but I will also add my solution for Xamarin.iOS / C # and those who want to install images through the constructor interface. I set the Selected Image and Image attributes through Interface Builder. Then, in the code, I defined the InitTabs() method, similar to this:

 public void InitTabs(){ HomeTab.SelectedImage = HomeTab.SelectedImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); HomeTab.Image = HomeTab.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); } 

Call InitTabs() in ViewDidLoad , and now the correct image will appear for both the selected and unselected states.

0
Dec 30 '15 at 1:39
source share

Here is a quick solution for Swift-Guys :)

 class CustomTabBar: UITabBar { required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) let btnNames = ["Title1", "Title2", "Title3", "Title4"] for (item, name) in zip(items!, btnNames) { item.image = UIImage(named: "bar\(name)Btn")?.imageWithRenderingMode(.AlwaysOriginal) item.selectedImage = UIImage(named: "bar\(name)SelectedBtn")?.imageWithRenderingMode(.AlwaysOriginal) item.title = name item.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.blackColor()], forState: .Normal) item.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.redColor()], forState: .Selected) } } } 

What exactly is happening here:

  • Create an array of btn headers and examine the image file names according to them.
  • Make For loop over tab bar and the newly created btn header array
  • Set the image barButtonItem and its selected image from the array
  • Set header text from array
  • Set header text color for .Normal and .Selected states

Setting the color of the text is important if you do not want the title bar of the element to be gray for .Normal and blue for .Selected, as by default. This is often true when you view custom images for tab bar items.

0
Apr 15 '16 at 15:39
source share

A quick version of showing selected and unselected images and headers with the UIAppearance API In your Appdelegate.m application, copy the following code if you have a base application. The following code assumes you have 4 tab bars.

 let tabBarController: UITabBarController = (self.window!.rootViewController as! UITabBarController) let tabBar:UITabBar = tabBarController.tabBar let tabBarItem1:UITabBarItem = tabBar.items![0] let tabBarItem2:UITabBarItem = tabBar.items![1] let tabBarItem3:UITabBarItem = tabBar.items![2] let tabBarItem4:UITabBarItem = tabBar.items![3] tabBarItem1.title = "Home"; tabBarItem2.title = "Maps"; tabBarItem3.title = "My Plan"; tabBarItem4.title = "Settings"; tabBarItem1.selectedImage = UIImage(named: "home_selected.png")! tabBarItem2.selectedImage = UIImage(named: "maps_selected.png")! tabBarItem3.selectedImage = UIImage(named: "myplan_selected.png")! tabBarItem4.selectedImage = UIImage(named: "settings_selected.png")! tabBarItem1.image = UIImage(named: "home.png")! tabBarItem2.image = UIImage(named: "maps.png")! tabBarItem3.image = UIImage(named: "myplan.png")! tabBarItem4.image = UIImage(named: "settings.png")! let tabBarBackground: UIImage = UIImage(named: "tabbar.png")! UITabBar.appearance().backgroundImage = tabBarBackground UITabBar.appearance().selectionIndicatorImage = UIImage(named: "tabbar_selected.png")! UITabBarItem.appearance().setTitleTextAttributes([ NSForegroundColorAttributeName : UIColor.whiteColor() ] , forState: .Normal) let titleHighlightedColor: UIColor = UIColor(red: 153 / 255.0, green: 192 / 255.0, blue: 48 / 255.0, alpha: 1.0) UITabBarItem.appearance().setTitleTextAttributes([ NSForegroundColorAttributeName : titleHighlightedColor ] , forState: .Highlighted) 
0
Aug 16 '16 at 11:28
source share

After trying all the other answers and struggling, as soon as they failed, I found the answer. Other answers do not seem to work in the current quick version. In Swift 2.3, this works for me. For those who are still having problems, try the following:

 tabBarItem.image = UIImage(named: "image_name") searchVC.tabBarItem.selectedImage = UIImage(named: "image_name_when_selected")?.imageWithRenderingMode(.AlwaysOriginal) 
0
12 Oct '16 at 6:03
source share



All Articles