0

I am using xcode 6.4 and using storyboard to set up Tab bar controller Item and its Images.

Issue 1- In storyboard on tab bar item selection, there are already option for Bar Item and Image selection. i have assigned Images on both field but Images are not changing at time of selection.Only default(black) image exists.

I have referred to this Link . Then also default (black) exists

Issue 2- In storyboard i have assigned all images on Bar Item and Image Selection and used given code then title is not visible in tab bar item. only image is working fine on selection.

Code-

- (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];
UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3];
UITabBarItem *tabBarItem5 = [tabBar.items objectAtIndex:4];

tabBarItem1.title = @"Home";
tabBarItem2.title = @"Search";
tabBarItem3.title = @"Cart";
tabBarItem4.title = @"Account";
tabBarItem5.title = @"More";



[tabBarItem1 setSelectedImage:[[UIImage imageNamed:@"HomeSelected.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

[tabBarItem2 setSelectedImage:[[UIImage imageNamed:@"SearchOpened.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

[tabBarItem3 setSelectedImage:[[UIImage imageNamed:@"CartOpened.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

[tabBarItem4 setSelectedImage:[[UIImage imageNamed:@"ProfileOpened.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

[tabBarItem5 setSelectedImage:[[UIImage imageNamed:@"MoreTabOpened.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];



// Change the tab bar background
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_selected.png"]];

// Change the title color of tab bar items
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                   [UIColor whiteColor], NSForegroundColorAttributeName,
                                                   nil] forState:UIControlStateNormal];
UIColor *titleHighlightedColor = [UIColor colorWithRed:255.0/255.0 green:109.0/255.0 blue:0.0/255.0 alpha:1.0];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                   titleHighlightedColor, NSForegroundColorAttributeName,
                                                   nil] forState:UIControlStateHighlighted];
return YES;
}

I've seen gone through iOS Docs, but could not find any useful update on these issues. please update me on it.

Community
  • 1
  • 1
ChenSmile
  • 3,401
  • 4
  • 39
  • 69

1 Answers1

0

You should create your custom tabbar

Useful link : http://swiftiostutorials.com/tutorial-custom-tabbar-storyboard/

Antoine Garcia
  • 143
  • 3
  • 9