0

While it was pretty easy to set it up in Objective C, I find it difficult with Swift.

I'm having a Page View Controller which leads me to a Tab Controller (kind of tutorial).

I'm trying to change the selected and unselected to my two images I've got in the Tab Bar, when selected It will chose "imageSelected.png" when not selected it will go with "imageNotSelected.png" (check the snippet code below)

Trying this snippet of code not doing anything

 tabBarItem.selectedImage = UIImage(named: "someImage.png")!.imageWithRenderingMode(.AlwaysOriginal)

Any help would be appreciated.

Edit: This is the Objective C I used in my older project which do work.

UITabBarController *tabBarController=(UITabBarController*)(self.window.rootViewController);
tabBarController.selectedIndex = 1; // SELTECT INDEX OF TAB BAR
UITabBar *tabBar=tabBarController.tabBar;
UITabBarItem *tabBarItem1=[[tabBar items] objectAtIndex:0]; //first tab bar
UITabBarItem *tabBarItem2=[[tabBar items] objectAtIndex:1];



UIImage *tabrBarImageOne = [[UIImage imageNamed:@“imageSelectedOne.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *tabrBarImageOneOff = [[UIImage imageNamed:@“imageNotSelectedOne.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

UIImage *tabBarImageTwo = [[UIImage imageNamed:@“imageSelectedTwo.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *tabBarImageTwooff = [[UIImage imageNamed:@“imageNotSelectedTwo.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

tabBarItem1 = [tabBarItem1 initWithTitle:@“title1” image:tabrBarImageOneOff selectedImage:tabrBarImageOne];

tabBarItem2 = [tabBarItem2 initWithTitle:@“title2” image:tabBarImageTwooff selectedImage:tabBarImageTwo];

Note: I've used it in the Objective C code in app delegate which now it's different since I need to load the code differently in each of the the VC I load in the ViewWillAppear.

XcodeNOOB
  • 2,135
  • 4
  • 23
  • 29
  • Show your Objective-C code that worked. You will probably discover the difference yourself. – Mundi Feb 22 '15 at 12:42

1 Answers1

0

You'd want to use .AlwaysTemplate instead if you want the tintColor to take effect.

Sean
  • 1,534
  • 12
  • 20